简体   繁体   中英

How to filter dataframe with selecting only last row of every hour?

Data is inconsistent.

I've tried to filter DataFrame with
df.Timestamp.dt.hour gives only hours,
df.Timestamp.dt.minute gives only minutes.

I need to filter for example every last entry of hour so 1:58, 2:54, 3:36, 4:44, etc.

I just need more efficient way, not explanation :)

我认为这应该工作:

df.sort_values('Date').groupby([df['Date'].dt.date, df['Date'].dt.hour], as_index=False).last()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM