# col is a series
t = col.apply(type).value_counts()
t_count = zip(t.index, t)
我的结果是t.index
为<type 'int'>
。我如何确定此类型是int。基本上我想要这样的东西
<type 'int'> == type(int) #It is returning false currently but i would like it to return true without converting it to a str and processing it
答案 0 :(得分:1)
您可以与int
进行比较:
col = pd.Series([1,2,'a','d','d',1.5,7.8])
t = col.apply(type).value_counts()
print (t)
<class 'str'> 3
<class 'float'> 2
<class 'int'> 2
dtype: int64
print (t.index == int)
[False False True]
print (t[t.index == int])
<class 'int'> 2
dtype: int64
也可以比较Series
:
print (col.apply(type) == int)
0 True
1 True
2 False
3 False
4 False
5 False
6 False
dtype: bool
print (col[col.apply(type) == int])
0 1
1 2
dtype: object