Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foo = ['amc', 'AAPL', 'gme', 'MSFT', 'TSLA']
- dfs = [pd.read_csv(f'{x}.csv').assign(Name=x.upper()) for x in foo]
- df = pd.concat(dfs).drop(columns=[ 'Open', 'High', 'Low'])
- df['Close/Last']=df['Close/Last'].str.replace('$',"", regex=True).astype(float)
- df['date']=pd.to_datetime(df['Date'])
- df=df.sort_values(by=['Name', 'date'])
- df=df.groupby(pd.PeriodIndex(df['date'], freq='M'))['Close/Last'].mean()
- print(df),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement