Both resample
and groupby
cause the resulting line plot to extend into January of next year. How do I stop the plot with the last data to more clearly see the data I actually have?
Here is the code and resulting plots.
# import painkiller data
import pandas as pd
import matplotlib.pyplot as plt
#import plotly.plotly as py
df = pd.read_csv('/Users/user/Documents/health/PainOverTime.csv',delimiter=',',header=0)
# plot bar graph of date and painkiller amount
times = pd.to_datetime(df.loc[:,'Time'])
# raw plot of data
ts = pd.Series(df.loc[:,'acetaminophen'].values, index = times,
name = 'Painkiller over Time')
# combine data by day
#groupby method
ts1 = df.groupby(times.dt.date)['acetaminophen'].sum()
fig1 = ts1.plot()
# resample method
ts2 = ts.resample('D').sum()
plt.figure()
fig2 = ts2.plot()