我在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
中列中的第一行值的任何想法答案 0 :(得分:2)
我认为你需要:
id
或者更好的是按Series.iat
或Series.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