我想找到5个最大值,并在列中显示哪一天,每个月的值
这是我已经尝试过的
ticker day price
0 000020.KR 2008-01-07 11120.0
1 000020.KR 2008-01-09 11060.0
2 000020.KR 2008-01-08 11040.0
3 000020.KR 2008-01-04 10960.0
4 000020.KR 2008-01-03 10880.0
这是我的代码
df = pd.read_sql_query(query, engine)
df['day'] = pd.to_datetime(df['day'])
per = df.day.dt.to_period("M")
g = df.groupby(['ticker',per])
a=g.apply(lambda x: x.nlargest(5,['price'])).reset_index(drop=True)
data = a
data
我想要什么,输出像这样
ticker month 2008-01-07 2008-01-09 2008-01-08 2008-01-04 2008-01-03
000020.KR 2008-01 11120.0 11060.0 11040.0 10960.0 10880.0
该怎么做?