pandas dataframe中列中第一个元素的类型

时间:2016-12-15 09:33:18

标签: python pandas

我在pandas df中有一张桌子

id   count
1     100
2     200
3     300

我想找到id列

下的第一个值

即' 1'以及' 1'

的类型 我可以用吗?

type(df['id'][0])

但它没有给我正确的结果。

它也尝试过使用它。

type(df.loc[df.index[0], 'id'].head(1))

如何获取pandas df

中列中的第一行值的任何想法

1 个答案:

答案 0 :(得分:2)

我认为你需要:

id

或者更好的是按Series.iatSeries.iloc选择print (type(df['id'].iat[0])) <class 'numpy.int64'> print (type(df['id'].iloc[0])) <class 'numpy.int64'> 列中的第一个值:

iat

In [64]: %timeit (type(df['id'].iat[0])) 100000 loops, best of 3: 10.6 µs per loop In [65]: %timeit (type(df['id'].iloc[0])) 100000 loops, best of 3: 16.9 µs per loop 更快:

ORDER BY