Plot time series chart with dates as multiple lines

Viewed 95

I have a pandas dataframe in following format

date ticks value

the ticks vary from 1 to 12 for each date. and there are corresponding values in value column I want to plot a time series line chart where x-axis represents ticks from 1 to 12, the y-axis represents value and there are multiple lines on the chart, each line representing a new date. How can i achieve this using pandas or any other library like matplotlib

1 Answers

Use:

# making sample df
df = pd.DataFrame({'date':['2020']*12+['2019']*12, 'ticks': list(range(1, 13))*2, 'value': np.random.randint(1,100,24)})

g = df.groupby('date').agg(list).reset_index()

import matplotlib.pyplot as plt
for i, row in g.iterrows():
    plt.plot(row['ticks'], row['value'], label = row['date']);
    plt.legend();

Output:

enter image description here

Related