1

I read a large Excel file into pandas using read_excel, and the file has date columns. When read into pandas, the dates default to a timestamp. Since the file is large, I would like to read the dates as a string.

If that is not possible, then I would at least like to export the date back to Excel in the same format as it is in the original file (e.g. "8/18/2009").

My two questions are:

Can I avoid converting the Excel date into a timestamp in pandas? If not possible, how can I write back the date in the original format efficiently?

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
Saurav
  • 21
  • 4
  • paste your code here? – Dev Jun 11 '20 at 13:12
  • DF=pd.read_excel(path, dtype=str,na_filter=False) I am using dtype = str because there are 100 of columns having leading 0s. But due to this small chunk- My input date : 03/29/2009 Getting changed to : 2009-03-29 00:00:00 The code is reading date as date timestamp – Saurav Jun 11 '20 at 13:27
  • I'm not familiar with [pandas.read_excel](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html). However, according to its api, I think `parse_dates` and `date_parser` may the parameters you interest. – Ynjxsjmh Jun 11 '20 at 14:13
  • Thanks for reviewing my question @ynjxsjmh but its still not working. I tried almost everything. – Saurav Jun 11 '20 at 14:17
  • If the answer from https://stackoverflow.com/q/34156830/10315163 doesn't help and pandas is silently converting the columns to datetime values. I think you can use the save-as function from Excel to save your excel as csv and use [pandas.read_csv](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) to do your function. Or you could consider [bug reports](https://github.com/pandas-dev/pandas#contributing-to-pandas-) to pandas. – Ynjxsjmh Jun 11 '20 at 14:29
  • Okay.. is there any way using which i can change format of all the date columns in the Data Frame? – Saurav Jun 11 '20 at 14:49

0 Answers0