我试图将 20 天滚动平均数据帧与 7 天滚动平均数据帧合并。我的代码如下:
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
import datetime as dt
start=dt.datetime.today()-dt.timedelta(90)
end=dt.datetime.today()
cl_price=pd.DataFrame(yf.download("MSFT AAPL FB GOOG AMZN IBM", start=start, end=end)['Adj Close'])
cl_price1=cl_price.dropna()
dailyretrun=cl_price.pct_change()
rolling20=dailyretrun.rolling(window=20).mean()
rolling7=dailyretrun.rolling(window=7).mean()
df=rolling20.join(rolling7)
我试过了pd.merge
,join
但我得到了以下错误。
ValueError: columns overlap but no suffix specified: Index(
['AAPL', 'AMZN', 'FB', 'GOOG', 'IBM', 'MSFT'], dtype='objec
t')