我有一个熊猫阵列,如下图所示。我想做以下事情:
目的是显示5年的历史为每个股票,目前我的表只有一年的空间。我在这里研究过,但是我找不到这个组合。提前谢谢!在
我用以下方法部分解决了这个问题:
# Create four copies of the dataframe
Yr2_df = df1
Yr3_df = df1
Yr4_df = df1
Yr5_df = df1
# Merge the 5 dataframe into one combined dataframe
df = pd.concat([df1, Yr2_df, Yr3_df, Yr4_df, Yr5_df],axis=0).sort_index().reset_index(drop=True)
但是,这并没有提供日期范围(每行应该有不同的年份:2017年、2016年等)。有什么建议吗?在
我就是这样添加日期范围的。这项挑战是循环使用年份列表,因为这比行列表要短。在
相关问题 更多 >
编程相关推荐