1

i got a data of year,month,day and value CSV enter image description here

then i try to convert the year,month and day into dataframe

WTS_clean['dateInt']=WTS_clean['Year'].astype(str) + WTS_clean['Month'].astype(str).str.zfill(2)+ WTS_clean['Day'].astype(str).str.zfill(2)
WTS_clean['DateDD'] = pd.to_datetime(WTS_clean['dateInt'], format='%Y%m%d')
WTS_clean['YearMonth'] = pd.to_datetime(WTS_clean.DateDD).dt.to_period('M')

Year int64 Month int64 Day int64 Value object Value_float float64 dateInt object DateDD datetime64[ns] YearMonth object dtype: object

Then i try to take the mean by each month

WTS_summary=WTS_clean.groupby(WTS_clean.YearMonth).agg({'Value_float':'mean'})
WTS_summary.columns = ['Average Temp'] 
WTS_summary.head()

enter image description here

and want to plot the graph

plt.figure()

plt.plot(WTS_summary.values, label='WTS Avg Temp', linewidth=1,alpha = 0.7,c='salmon')

enter image description here

The question is how the x axis will start from 0 instead of 2009-03,2009-04 etc ?

How to change the x axis back to the value of grouped dt-WTS_summary?

Thanks a lot

0 Answers0