Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- import seaborn as sns
- from matplotlib.animation import FuncAnimation
- import numpy as np
- 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'])
- print(df)
- # df=df.groupby(pd.PeriodIndex(df['date'], freq='M'))['Close/Last'].mean().reset_index()
- df=df.groupby(pd.PeriodIndex(df['date'], freq='M')).agg({'Close/Last': (np.mean),'Volume':'first','Name':'first'})
- df=df.reset_index()
- print(df)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement