![](/img/trans.png)
[英]Python: Create dataframe from a list where each new row starts at a specific list index
[英]Python - How to create a new dataframe for each month out of a list of data
df['date'] = pd.to_datetime(df['date'])
df['year-month'] = df['date'].map(lambda x: x.strftime('%Y-%m'))
df = df.sort_values(['year-month', 'MarketCap'], ascending=[True, False])
df = df.groupby('year-month').apply(lambda x: x[x['MarketCap'] > x['MarketCap'].quantile(.1)]).reset_index(1, drop = True)
df = df.drop(columns=['year-month']).reset_index().drop(columns=['year-month'])
首先创建一个只包含年和月的列。
然后对year-month
和MarketCap
列进行升序和降序排序。
按MarketCap
列分组,并过滤掉每组中低于 10% 的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.