0

I have a csv file that I am reading into pandas. The file has a field called Period with values : 31DEC2017,31JAN2018 etc. Pandas reads it as a string, but I need to read it as a date. How do I do it? I tried:

pd.read_csv("test.csv" ,dtype={'PERIOD':time})

But it does not work. I even tried :

dtype={'PERIOD':date})
dtype={'PERIOD':datetime})

Still gives me error

akshat
  • 1,219
  • 1
  • 8
  • 24
Victor
  • 16,609
  • 71
  • 229
  • 409
  • `parse_dates ` https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html – BENY May 16 '18 at 18:00
  • The answer in the linked question is an absolute mess, but I'd recommend reading as string and using `pd.to_datetime` once it's in memory. Otherwise, `parse_dates=['PERIOD']` – cs95 May 16 '18 at 18:03

0 Answers0