Python 熊猫打印所有 dtypes
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23168416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas printing ALL dtypes
提问by SColvin
This seems like a very simple problem, however it's driving me round the bend. I'm sure it should be solved by RTFM, but I've looked at the options and I can see the one to fix it.
这似乎是一个非常简单的问题,但它驱使我绕过弯道。我确定它应该由 RTFM 解决,但我已经查看了选项,我可以看到修复它的选项。
I just want to print the dtypes of all columns, currently I'm getting:
我只想打印所有列的 dtypes,目前我得到:
print df.dtypes
#>
Date object
Selection object
Result object
...
profit float64
PL float64
cumPL float64
Length: 11, dtype: object
I've tried setting options display.max_row
, display.max_info_row
, display.max_info_columns
all to no avail.
我试过设置 options display.max_row
, display.max_info_row
,display.max_info_columns
都无济于事。
What am i doing wrong?
我究竟做错了什么?
Pandas version = 0.13.1
熊猫版本 = 0.13.1
Update:
更新:
Turns out I was being and idiot and hadn't set display.max_row
to a high enough value.
原来我是个白痴,没有设置display.max_row
足够高的值。
Solution was:
解决方案是:
pd.set_option('display.max_rows', 20)
回答by Mshendy
another way around is to group by dtype as follows:
另一种方法是按 dtype 分组,如下所示:
x = df.columns.to_series().groupby(df.dtypes).groups
x
{dtype('object'): ['Date', 'Selection', 'Result'], dtype('float64'): ['profit', 'PL', 'cumPL']
回答by chok68
I tried this and worked:
我试过这个并工作:
df.info(verbose=True)
回答by el ks
Do this:
做这个:
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
print(df.dtypes)