Alex
Alex

Reputation: 173

Pandas: Finding values ​of type datetime.time in a column

I am trying to find values ​​like datetime.time in column time:

>>> import pandas
>>> import datetime
>>> df = pandas.read_excel('Doc.xlsx')

This is how it looks:

>>> df['time']
0         21:34:00

I looked at the type:

>>> for i in df['time']: type(i)
...
>>> <class 'datetime.time'>

I tried using a mask but it doesn't work:

>>> df.loc[df['time'] == type(datetime.time)]
Empty DataFrame
Columns: [time]
Index: []

What method can I use to search?

Upvotes: 0

Views: 31

Answers (1)

dukkee
dukkee

Reputation: 1122

df.loc[df['time'].apply(lambda x: isinstance(x, datetime.time))]

Upvotes: 1

Related Questions