0

I have a csv that contains different type of format, however, when I read in the data even with specifying the data dtype as object or dtype as str, it still changes my format.

Example of my csv as belows:

Date  Cost
3/31/2015  3363
2020-16-07  5515

When I perform

a = pd.read_csv('xxxx.csv',dtype={'Date':object})

it returns

Date  Cost
2015-3-31  3363
2020-16-07  5515

When I tries to check its type, it appears to the string, however it changed the date.

I've also tried to read it in as the below, however it still yield me the same result

a = pd.read_csv('xxxx.csv',dtype={'Date':str})

Can I read it as original state so I can convert it to the same format?

Wing Shum
  • 472
  • 6
  • 19
  • Try to use `read_excel()` function instead. [documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html) – Pooria_T Sep 02 '20 at 09:40
  • Sorry, its read_csv, mistake for the file. – Wing Shum Sep 02 '20 at 09:42
  • This [link](https://stackoverflow.com/questions/13999850/how-to-specify-date-format-when-using-pandas-to-csv) will help you to change your date format. You can use *lambda* to do it. – Pooria_T Sep 02 '20 at 09:45
  • Sorry, my data have two set of date format, when it read the csv, it combines and I am unable to differentiate anymore – Wing Shum Sep 02 '20 at 09:51

0 Answers0