Reputation: 111
I am trying to plot a time series data. The dataframe looks like this
[1]:Index ship_date cost_amount
0 1/8/2010 34276
1 1/8/2010 12375
2 1/8/2011 12343
3 2/9/2011 15435
[2]: df1.plot(figsize(20,5))
I am trying to plot the data but for some reason plot doesn't have x-axis in ascending order. How do I get the plot with date ascending or descending order ?
Upvotes: 1
Views: 282
Reputation: 394469
Your problem (as spotted by @ J Richard Snape) is that your dates are in fact strings so it's ordered lexicographically.
You should convert to datetime dtype:
df1['Ship_date'] = pd.to_datetime(df1['Ship_date'])
After which it should maintain the expected order.
Upvotes: 2