Combine series by date

a 夏天 提交于 2021-01-29 08:22:44

问题


The following 2 series of stocks in a single excel file:

Can be combined using the date as index?

The result should be like this:


回答1:


You need a simple df.merge() here:

df = pd.merge(df1, df2, left_index=True, right_index=True, how='outer')

OR

df = df1.join(df2, how='outer')



回答2:


I am trying this:

df3 = pd.concat([df1, df2]).sort_values('Date').reset_index(drop=True)

or

df3 = df1.append(df2).sort_values('Date').reset_index(drop=True)


来源:https://stackoverflow.com/questions/64212463/combine-series-by-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!