Pandas Series Find Index Of A Certain Type
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, dt
Solution 1:
Say you have
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]
You can do
df[df.ex.transform(type) == datetime.time]
To get
ex
1 02:19:53
Details:
transform(type)
yields the type of your entries
0 <class 'int'>
1 <class 'datetime.time'>
2 <class 'str'>
3 <class 'list'>
Then
df.ex.transform(type) == datetime.time
0 False
1 True
2 False
3 False
Post a Comment for "Pandas Series Find Index Of A Certain Type"