pandas 计算熊猫数据框中的数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32337380/
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
Count data types in pandas dataframe
提问by Gilaztdinov Rustam
I have pandas.DataFramewith too much number of columns.
我有pandas.DataFrame太多的列。
I call:
我打电话:
In [2]: X.dtypes
Out[2]: VAR_0001 object
VAR_0002 int64
...
VAR_5000 int64
VAR_5001 int64
And I can't understand what types of data I have between VAR_0002and VAR_5000
我无法理解我在VAR_0002和之间拥有哪些类型的数据VAR_5000
It's can be int64, int8, float64and so on. I see in this blognative type of pandas.DataFramebut I think this is wrong information. How can I get this?
它可以是int64,int8,float64等。我在这个博客中看到原生类型的,pandas.DataFrame但我认为这是错误的信息。我怎样才能得到这个?
And other question. When I work on PC (Windows) and call this:
还有其他问题。当我在 PC (Windows) 上工作并调用它时:
In [3]: X.dtypes[X.dtypes.map(lambda x: x=='bool')]
I get several columns with this type of data. But when I use this command on Mac, I get nothing. WAT?
我得到了几列包含这种类型的数据。但是当我在 Mac 上使用这个命令时,我什么也得不到。哇?
回答by EdChum
To answer your first question do the following:
要回答您的第一个问题,请执行以下操作:
df.dtypes.value_counts()
Example:
例子:
In [4]:
df = pd.DataFrame({'a':[0], 'b':['asds'], 'c':[0]})
df.dtypes
Out[4]:
a int64
b object
c int64
dtype: object
In [5]:
df.dtypes.value_counts()
Out[5]:
int64 2
object 1
dtype: int64

