I'm currently trying to organize data of avocado prices that was used in Sentdex data analysis video: https://www.youtube.com/watch?v=DamIIzp41Jg&list=PLQVvvaa0QuDfSfqQuee6K8opKtZsh7sA9&index=2
Here is the dataset that I am using: https://www.kaggle.com/neuromusic/avocado-prices
I want to group the dates for the state of California by the month to ultimately graph month with average price.
I've currently written the following code:
import pandas as pd
df = pd.read_csv(avocado.csv")
cali = pd.DataFrame()
region_df = df.copy()[ df['region'] == "California" ]
cali = region_df[["Date","AveragePrice"]]
M=["Jan",'Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
cali = region_df[["Date","AveragePrice"]]
cali["Month"] = "NA"
cali.loc[cali.Date.str.contains('2015-01'), 'Month'] = M[0]
cali.set_index("Date", inplace=True)
cali.sort_index(inplace=True)
This is the output for the table:
To do this for every month from 2015 to 2018 would be messy and tedious, I was wondering if there is a more efficient method to group dates by month.