1

I have trying to merge the 20 days rolling mean daataframe witht he 7 days rolling mean dataframe. My code is as follows:

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)

I tried pd.merge and join but I am getting the below error.

ValueError: columns overlap but no suffix specified: Index(
['AAPL', 'AMZN', 'FB', 'GOOG', 'IBM', 'MSFT'], dtype='objec
t')
raptorzee
  • 151
  • 1
  • 11

1 Answers1

1

This error indicates that the two dataframes have columns with same name

To join the dataframes use lsuffix and rsuffix in the following way

df=rolling20.join(rolling7,lsuffix='_ls', rsuffix='_rs')
safiqul islam
  • 546
  • 3
  • 13