Use GroupBy.nth
by dates extracted by Series.dt.date
:
df1 = df.groupby(df['Datetime'].dt.date).nth([2,5])
Or if need original not changed data use GroupBy.cumcount
for counter and compare by Series.isin
, but subtract 1
because python counts from 0
and filter by boolean indexing
:
df1 = df[df.groupby(df['Datetime'].dt.date).cumcount().isin([1,4])]
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.