EP1986
EP1986

Reputation: 873

pandas: plot histogram with time on x axis

I have a Dataframe df like that:

Datetime                 Dollar

2009-08-01 00:00:00        87

2009-08-01 00:15:00        32 

2009-08-01 00:30:00        19 

2009-08-01 00:45:00       128

If I try df.hist(), I only get the values (ascending) on the x axis and the specific quantity on the y axis. But I need the timestamp on the x axis for analyzing the changes in value over the time.

Upvotes: 3

Views: 3445

Answers (1)

Alex Riley
Alex Riley

Reputation: 176730

Perhaps df.plot() would be suitable here. You could write:

df.plot('Datetime', 'Dollar', kind='bar', rot=45)

which gives:

enter image description here

To detail the arguments used in plot above: 'Datetime' and 'Dollar' indicate the columns to use for the x-axis and y-axis values respectively; the kind keyword argument is used to specify a bar chart; the rot keyword argument simply rotates the x-axis labels for readability.

Upvotes: 2

Related Questions