1

I would like to plot a bar plot. It shows the money for one day. The plot looks fine, but it displays one day like this "%y-%m-%d %h:%m:%s". It would be nice, when it shows only "%y-%m-%d".

My dataframe looks like this:

            Erdtemp  Heizung   Money_H
DatumZeit                             
2021-04-28   4047.5       73  0.003613
2021-04-29  27469.4      504  0.024948
2021-04-30  27450.6      488  0.024156
2021-05-01  28186.3      420  0.020790
2021-05-02   9006.1       71  0.003515

I use this line to plot it:

Tab2_count.plot(kind='bar', y='Money_H', xlabel='Date', ylabel='Euro')

And the plot looks like this:

enter image description here

Is there any easy way to get rid of the 00:00:00 ?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
  • little addition to the linked question; after assigning the plot to a variable `ax`, you can set the labels e.g. like `ax.set_xticklabels(Tab2_count.index.strftime('%Y-%m-%d').to_series())` in your case. – FObersteiner May 02 '21 at 08:41
  • Thank you very much. Your way works also flawlessly. `ax = Tab2_count.plot(kind='bar', y='Money_H', xlabel='Date', ylabel='Euro') ax.set_xticklabels(Tab2_count.index.strftime('%Y-%m-%d').to_series())` – Kai_hismelf May 02 '21 at 16:54

1 Answers1

1

You can use pandas.DatetimeIndex.date() to get date part from DatetimeIndex object. Then use it before plot or after plot.

df.index = df.index.date

df.plot(kind='bar', y='Money_H', xlabel='Date', ylabel='Euro')

Or

axes = df.plot(kind='bar', y='Money_H', xlabel='Date', ylabel='Euro')

axes.set_xticklabels(df.index.date)
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52