pandas 系列找到特定类型的索引 [英] pandas series find index of a certain type

查看:76
本文介绍了 pandas 系列找到特定类型的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我df的其中一列主要包含datetime.time类型

one of the columns of my df contains mostly datetime.time types

all_cities['Result'].head()
0    02:19:53
1    02:20:10
2    02:20:52
3    02:37:19
4    02:38:05

Name: Result, dtype: object

但是all_cities ['Result '] [0]

but, all_cities['Result'][0]

datetime.time(2, 19, 53)

我如何找到不同类型的单元格索引(不是datetime.time)?

how can i find the index of cell of different types(not datetime.time)?

推荐答案

说你有

df = pd.DataFrame({'ex': [1, datetime.time(2,19,53), "string", [1,2,3]]})

    ex
0   1
1   02:19:53
2   string
3   [1, 2, 3]

您可以做

df[df.ex.transform(type) == datetime.time]

要获取

ex
1   02:19:53






详细信息:

transform(type)产生条目的类型

0              <class 'int'>
1    <class 'datetime.time'>
2              <class 'str'>
3             <class 'list'>

然后

 df.ex.transform(type) == datetime.time

0    False
1     True
2    False
3    False

这篇关于 pandas 系列找到特定类型的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆