是否有一种方法可以在交互或脚本执行模式下扩大输出的显示?
具体来说,我在Pandas DataFrame上使用了describe()函数。当DataFrame是五列(标签)宽时,我得到了我想要的描述性统计数据。然而,如果DataFrame有更多的列,统计数据将被抑制,并返回如下内容:
>> Index: 8 entries, count to max
>> Data columns:
>> x1 8 non-null values
>> x2 8 non-null values
>> x3 8 non-null values
>> x4 8 non-null values
>> x5 8 non-null values
>> x6 8 non-null values
>> x7 8 non-null values
无论有6列还是7列,都给出“8”值。“8”指什么?
我已经尝试过将IDLE窗口拖大,以及增加“配置IDLE”宽度选项,但无济于事。
似乎前面所有的答案都能解决这个问题。还有一点:你可以使用(auto-complete-able)而不是pd.set_option('option_name'):
pd.options.display.width = None
参见Pandas文档:选项和设置:
选项有一个完整的“虚线风格”,不区分大小写的名称(例如。
display.max_rows)。的属性可以直接获取/设置选项
顶级选项属性:
在[1]中:导入熊猫为pd
在[2]:pd.options.display.max_rows中
[2]: 15
在[3]:pd.options.display中。Max_rows = 999
在[4]:pd.options.display.max_rows中
出[4]:999
[…]
对于max_…参数:
max_rows and max_columns are used in __repr__() methods to decide if to_string() or info() is used to render an object to a string. In case Python/IPython is running in a terminal this can be set to 0 and pandas will correctly auto-detect the width the terminal and swap to a smaller format in case all columns would not fit vertically. The IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to do correct auto-detection. ‘None’ value means unlimited. [emphasis not in original]
对于width参数:
以字符为单位的显示宽度。如果Python/IPython在终端中运行,可以将其设置为None, pandas将正确地自动检测宽度。请注意,IPython notebook、IPython qtconsole或IDLE不在终端中运行,因此不可能正确地检测宽度。
import pandas as pd
pd.set_option('display.max_columns', 100)
pd.set_option('display.width', 1000)
SentenceA = "William likes Piano and Piano likes William"
SentenceB = "Sara likes Guitar"
SentenceC = "Mamoosh likes Piano"
SentenceD = "William is a CS Student"
SentenceE = "Sara is kind"
SentenceF = "Mamoosh is kind"
bowA = SentenceA.split(" ")
bowB = SentenceB.split(" ")
bowC = SentenceC.split(" ")
bowD = SentenceD.split(" ")
bowE = SentenceE.split(" ")
bowF = SentenceF.split(" ")
# Creating a set consisting of all words
wordSet = set(bowA).union(set(bowB)).union(set(bowC)).union(set(bowD)).union(set(bowE)).union(set(bowF))
print("Set of all words is: ", wordSet)
# Initiating dictionary with 0 value for all BOWs
wordDictA = dict.fromkeys(wordSet, 0)
wordDictB = dict.fromkeys(wordSet, 0)
wordDictC = dict.fromkeys(wordSet, 0)
wordDictD = dict.fromkeys(wordSet, 0)
wordDictE = dict.fromkeys(wordSet, 0)
wordDictF = dict.fromkeys(wordSet, 0)
for word in bowA:
wordDictA[word] += 1
for word in bowB:
wordDictB[word] += 1
for word in bowC:
wordDictC[word] += 1
for word in bowD:
wordDictD[word] += 1
for word in bowE:
wordDictE[word] += 1
for word in bowF:
wordDictF[word] += 1
# Printing term frequency
print("SentenceA TF: ", wordDictA)
print("SentenceB TF: ", wordDictB)
print("SentenceC TF: ", wordDictC)
print("SentenceD TF: ", wordDictD)
print("SentenceE TF: ", wordDictE)
print("SentenceF TF: ", wordDictF)
print(pd.DataFrame([wordDictA, wordDictB, wordDictB, wordDictC, wordDictD, wordDictE, wordDictF]))
输出:
CS Guitar Mamoosh Piano Sara Student William a and is kind likes
0 0 0 0 2 0 0 2 0 1 0 0 2
1 0 1 0 0 1 0 0 0 0 0 0 1
2 0 1 0 0 1 0 0 0 0 0 0 1
3 0 0 1 1 0 0 0 0 0 0 0 1
4 1 0 0 0 0 1 1 1 0 1 0 0
5 0 0 0 0 1 0 0 0 0 1 1 0
6 0 0 1 0 0 0 0 0 0 1 1 0