我正在使用IPython Notebook,并希望能够通过提交简单的DataFrame名称来控制返回哪种类型的输出。例如:
df = DataFrame({"A": [1,2,3], "B": [4,5,6]})
df
将始终返回网格表示,因为它是一个如此小的DataFrame。但是,较大的DataFrame将以HTML表示形式显示(至少在笔记本中使用我的设置)。也就是说,只要不超过大约15列,在这种情况下,表示就像这样:
<class 'pandas.core.frame.DataFrame'>
Index: 35 entries, 6215.0 to 6028.0
Data columns:
District Name 35 non-null values
Total Percent Pass 35 non-null values
GE Percent Pass 35 non-null values
SE Percent Pass 3 non-null values
White Percent Pass 11 non-null values
Black Percent Pass 23 non-null values
Hispanic Percent Pass 21 non-null values
Asian Percent Pass 4 non-null values
PI Percent Pass 0 non-null values
AI Percent Pass 0 non-null values
Other Percent Pass 0 non-null values
EcDis Percent Pass 29 non-null values
Non EcDis Percent Pass 26 non-null values
Total Percent Pass_D 35 non-null values
GE Percent Pass_D 35 non-null values
SE Percent Pass_D 31 non-null values
White Percent Pass_D 27 non-null values
Black Percent Pass_D 35 non-null values
Hispanic Percent Pass_D 35 non-null values
Asian Percent Pass_D 19 non-null values
PI Percent Pass_D 0 non-null values
AI Percent Pass_D 0 non-null values
Other Percent Pass_D 0 non-null values
EcDis Percent Pass_D 35 non-null values
Non EcDis Percent Pass_D 35 non-null values
Comparative 35 non-null values
dtypes: float64(25), object(1)
我希望能够随意强制执行此类表示(最后一个),而无需在笔记本中关闭选项。有没有办法做到这一点?
答案 0 :(得分:4)
扩展您的示例,您只需使用df.info
In [21]: df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3 entries, 0 to 2
Data columns:
A 3 non-null values
B 3 non-null values
dtypes: int64(2)