【发布时间】:2021-01-13 07:35:26
【问题描述】:
我有以下股票清单:
对于每个我想按月份分开的解释图:
通过这种分离,我可以执行每天的累积回报,并按每个股票代码的最大和最小累积回报分开。
我正在从 SO 执行以下操作(来自另一个股票列表的示例): Call a report from a dictionary of dataframes:
data_dict = dict() # create an empty dict here
for k, df in df_dict.items():
df_dict[k]['Return %'] = df.iloc[:, 0].pct_change(-1)*100
# aggregate the max and min of Return
mm = df_dict[k]['Return %'].agg(['max', 'min'])
# add it to the dict, with ticker as the key
data_dict[k] = {'max': mm.max(), 'min': mm.min()}
# convert to a dataframe if you want
mm_df = pd.DataFrame.from_dict(data_dict, orient='index')
# display(mm_df)
max min
aapl 8.70284 -4.90070
msft 6.60377 -4.08443
这会导致对列表中的股票进行线性分析,并且不会像我希望按照上图那样按天分开。..
问题:
- 如何插入一个步骤来按月份分割,然后执行上述代码?
【问题讨论】:
-
有人可以帮帮我吗?
标签: python pandas dictionary