0

I was looking to import a csv file and plot it, but to my surprise the plot is looking wierd because the date format changes after 11th value. Pandas is interpreting the date format as incorrect.

My dataset starts from 2nd April 2016. the csv file is this

enter image description here

the df.head shows this

[enter image description here]

from 11th datapoint , the head() gives one format, then from 12th datapoint the format changes. This has confused me because the plot function also gives weird plot like this

[enter image description here]

Can someone please guide me where am i making a mistake. I want to plot sales data from 02nd April 2016 to 15th Feb 2019 in a series. FYI: the excel sheets look like this

[enter image description here]

bunji
  • 5,063
  • 1
  • 17
  • 36

1 Answers1

0

The issue starts when first number could not be parsed as Month number (13). This is actually not an issue, it starts working as you axpected after 12, so the first number was by default treated as month. I assume that you are parsing .csv or something like that, so dayfirst flag would be helpful: pd.read_csv('data.csv', dayfirst=True, parse_dates=True, index_col=[0]) (like in this answer Read csv with dd.mm.yyyy in Python and Pandas)

or refer to Pandas timeseries