Skip to content Skip to sidebar Skip to footer

How To Use Pandas Series To Plot Two Time Series Of Different Lengths/starting Dates?

I am plotting several pandas series objects of 'total events per week'. The data in the series events_per_week looks like this: Datetime 1995-10-09 45 1995-10-16 63 1995

Solution 1:

I really don't get where you're having problems. I tried to recreate a piece of the dataframe, and it plotted with no problems.

import numpy, matplotlib
data = numpy.array([45,63,83,91,101])
df1 = pd.DataFrame(data, index=pd.date_range('2005-10-09', periods=5, freq='W'), columns=['events'])
df2 = pd.DataFrame(numpy.arange(10,21,2), index=pd.date_range('2003-01-09', periods=6, freq='W'), columns=['events'])
matplotlib.pyplot.plot(df1.index, df1.events)
matplotlib.pyplot.plot(df2.index, df2.events)
matplotlib.pyplot.show()

Using Series instead of Dataframe:

ds1 = pd.Series(data, index=pd.date_range('2005-10-09', periods=5, freq='W'))
ds2 = pd.Series(numpy.arange(10,21,2), index=pd.date_range('2003-01-09', periods=6, freq='W'))
matplotlib.pyplot.plot(ds1)
matplotlib.pyplot.plot(ds2)
matplotlib.pyplot.show()

Post a Comment for "How To Use Pandas Series To Plot Two Time Series Of Different Lengths/starting Dates?"