Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在打印时阻止pandas数据表被截断?_Python_Django_Pandas_Dataframe_Python 3.7 - Fatal编程技术网

Python 如何在打印时阻止pandas数据表被截断?

Python 如何在打印时阻止pandas数据表被截断?,python,django,pandas,dataframe,python-3.7,Python,Django,Pandas,Dataframe,Python 3.7,我编写了两个字符串的代码,然后比较它们是否有相似的单词。然后用这些数据生成一个表 我的问题是它总是一分为二。我需要纠正这一点,以便能够将其合并到HTML中。我非常感谢您的帮助,并提前表示感谢!:) 我也试着只打印第一行 完整代码: import string from os import path import pandas as pd pd.set_option('display.max_columns', None) #prevents trailing elipses pd.set_

我编写了两个字符串的代码,然后比较它们是否有相似的单词。然后用这些数据生成一个表

我的问题是它总是一分为二。我需要纠正这一点,以便能够将其合并到HTML中。我非常感谢您的帮助,并提前表示感谢!:)

我也试着只打印第一行

完整代码:

import string
from os import path

import pandas as pd
pd.set_option('display.max_columns', None) #prevents trailing elipses
pd.set_option('display.max_rows', None)
import os.path

BASE = os.path.dirname(os.path.abspath(__file__))

file1 = open(os.path.join(BASE, "samp.txt"))
sampInput=file1.read().replace('\n', '')
file2 = open(os.path.join(BASE, "ref.txt"))
refInput=file2.read().replace('\n', '')

sampArray = [word.strip(string.punctuation) for word in sampInput.split()]
refArray = [word.strip(string.punctuation) for word in refInput.split()]

out=pd.DataFrame(index=sampArray,columns=refArray)

for i in range(0, out.shape[0]): #from 0 to total number of rows
        for word in refArray: #for each word in the samplearray

                df1 = out.iloc[0, 0:16].copy()
                top = out.ix[:1, :17]

                out.ix[i,str(word)] = out.index[i].count(str(word))
#print(out)
print(top)
#print(df1)

您可以设置如何显示数据帧的选项:

pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 150)

如果在打印任何内容之前添加此项,则数据帧将以您期望的格式打印

它不会拆分为两个数据帧;当dataframe有太多列时,它只会自动打印在另一行上(请参阅反斜杠)。您可以尝试从IPython.display导入display
,然后用
显示(顶部)
代替打印。我明白了。非常感谢。我尝试了你推荐的方法,但不幸的是,它给出了相同的输出。主要的问题是,这会影响我将数据呈现到网页到表格中的能力吗?如果您尝试导出图形,这可能会有所帮助:非常感谢,我会找到它:)它成功了,非常感谢xyzjayne xDcheers成功了!我已经将前2名设置为无。。。按照您的建议添加宽度可以纠正此问题。亲切的问候!NP请注意,这不会改变您的数据帧,但会改变它的显示方式。而且,如果您只想暂时设置选项,您可以在以后使用
pd.reset\u选项('display.max_rows | display.max columns | display.width')将其更改回默认值。
。(参数是一个正则表达式-请参阅中的文档。)