0

In the following snippet I want to do the format transformation inplace without having to keep another temporary variable (df)

df = other_df.set_index('datetime_created').groupby(pd.TimeGrouper("M")).aggregate({...complex dict...})
df.index = df.index.format(formatter=lambda x: x.strftime('%b %Y'))
df.plot.bar(sharex=True, stacked=True)
Flo
  • 1,367
  • 1
  • 13
  • 27

1 Answers1

0

I guess you could just format the axis after plotting? One example:

df = pd.DataFrame(np.random.rand(10,2), 
                 index=pd.date_range('2005-01-01', freq='M', periods=10))
ax = df.plot(kind='bar', sharex=True, stacked=True)
ax.set_xticklabels([x.strftime('%b %Y') for x in df.index])
plt.show()

Result graph

Julien Marrec
  • 11,605
  • 4
  • 46
  • 63