2 回答
TA贡献1876条经验 获得超6个赞
让我们尝试isin一下groupby head
df.index=pd.to_datetime(df.index)
toremove = df.groupby(df.index.date).head(1).index.strftime('%Y-%m-%d %H:%M')
df = df[~df.index.strftime('%Y-%m-%d %H:%M').isin(toremove)]
df
price
quote_ts
2020-05-15 15:00:01.234517 1300
2020-05-16 14:01:00.582517 1400
2020-05-17 14:02:00.524567 1900
TA贡献1831条经验 获得超4个赞
用于groupby.rank创建布尔掩码
s = pd.to_datetime(df.index)
m = ((s.floor('Min').to_series().groupby(s.date).rank(method='dense') > 1)
.to_numpy())
df_final = df[m]
Out[338]:
price
quote_ts
2020-05-15 15:00:01.234517 1300
2020-05-16 14:01:00.582517 1400
2020-05-17 14:02:00.524567 1900
添加回答
举报