Advertisement
g96

Untitled

g96
Apr 5th, 2022
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. import seaborn as sns
  4. from matplotlib.animation import FuncAnimation
  5. import numpy as np
  6.  
  7.  
  8.  
  9. foo = ['amc', 'AAPL', 'gme', 'MSFT', 'TSLA']
  10. dfs = [pd.read_csv(f'{x}.csv').assign(Name=x.upper()) for x in foo]
  11. df = pd.concat(dfs).drop(columns=[ 'Open', 'High', 'Low'])
  12.  
  13. df['Close/Last']=df['Close/Last'].str.replace('$',"", regex=True).astype(float)
  14.  
  15.  
  16. df['date']=pd.to_datetime(df['Date'])
  17. df=df.sort_values(by=['Name', 'date'])
  18. print(df)
  19. # df=df.groupby(pd.PeriodIndex(df['date'], freq='M'))['Close/Last'].mean().reset_index()
  20.  
  21. df=df.groupby(pd.PeriodIndex(df['date'], freq='M')).agg({'Close/Last': (np.mean),'Volume':'first','Name':'first'})
  22. df=df.reset_index()
  23.  
  24. print(df)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement