import pandas as pd
df = pd.read_csv('vend.csv')
print(df.head())
df['Date'] = pd.to_datetime(df["TransDate"])
df['Month'] = df['Date'].dt.month_name()
def month_count(month):
return df[df['Month'] == month].shape[0]
month_count('March')
def total_price(month):
return df[df['Month'] == month]['RPrice'].sum()
total_price('March')
df_out = pd.DataFrame()
df_out['Month'] = df['Month'].unique()
df_out['transactions'] = df_out['Month'].map(month_count)
df_out['total price'] = df_out['Month'].map(total_price)
df_out.to_csv('df_out.csv', index=False)
print(df_out)