Advertisement
g96

Untitled

g96
Apr 5th, 2022
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1.  
  2. foo = ['amc', 'AAPL', 'gme', 'MSFT', 'TSLA']
  3. dfs = [pd.read_csv(f'{x}.csv').assign(Name=x.upper()) for x in foo]
  4. df = pd.concat(dfs).drop(columns=[ 'Open', 'High', 'Low'])
  5.  
  6. df['Close/Last']=df['Close/Last'].str.replace('$',"", regex=True).astype(float)
  7.  
  8.  
  9. df['date']=pd.to_datetime(df['Date'])
  10. df=df.sort_values(by=['Name', 'date'])
  11.  
  12. df=df.groupby(pd.PeriodIndex(df['date'], freq='M'))['Close/Last'].mean()
  13.  
  14. print(df),
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement