["python","pandas","matplotlib"]
How to plot different groups of data from a dataframe into a single figure

I have a temperature file with many years of temperature records in the format below: 2012-04-12,16:13:09,20.6 2012-04-12,17:13:09,20.9 2012-04-12,18:13:09,20.6 2007-05-12,19:13:09,5.4 2007-05-12,20:13:09,20.6 2007-05-12,20:13:09,20.6 2005-08-11,11:13:09,20.6 2005-08-11,11:13:09,17.5 2005-08-13,07:13:09,20.6 2006-04-13,01:13:09,20.6 Every year has different numbers of time of records, so the pandas datetimeindices are all different. I want to plot the different year's data in the same figure for comparison: The X-axis is datetimeindices from Jan to Dec The Y-axis is the temperature How should I go about doing this?
Chang's answer shows how to plot a different DataFrame on the same axes. In this case, all of the data is in the same dataframe, so it's better to use groupby and unstack. Alternatively, pandas.DataFrame.pivot_table can be used. dfp = df.pivot_table(index='Month', columns='Year', values='value', aggfunc='mean') When using pandas.read_csv, names= creates column headers when there are none in the file. The 'date' column must be parsed into datetime64[ns] Dtype so the .dt extractor can be used to extract the month and year. import pandas as pd # given the data in a file as shown in the op df = pd.read_csv('temp.csv', names=['date', 'time', 'value'], parse_dates=['date']) # create additional month and year columns for convenience df['Year'] = df.date.dt.year df['Month'] = df.date.dt.month # groupby the month a year and aggreate mean on the value column dfg = df.groupby(['Month', 'Year'])['value'].mean().unstack() # display(dfg) Year 2005 2006 2007 2012 Month 4 NaN 20.6 NaN 20.7 5 NaN NaN 15.533333 NaN 8 19.566667 NaN NaN NaN Now it's easy to plot each year as a separate line. The OP only has one observation for each year, so only a marker is displayed. ax = dfg.plot(figsize=(9, 7), marker='.', xticks=dfg.index)