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:
import pandas as pd
df = pd.read_excel(
"file_to_read.xlsx",
sheet_name="sheetname",
)
writer = pd.ExcelWriter(
"file_to_write.xlsx",
engine="xlsxwriter",
datetime_format="mm/dd/yyyy",
)
df.to_excel(
writer,
index=False,
header=True,
sheet_name="sheetname",
)
this is similar as issue here. Leave dates as strings using read_excel function from pandas in python
check the answers:
pandas.read_excel(xlsx, sheet, converters={'Date': str})
df['Date'][0].strftime('%Y/%m/%d')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With