I am trying to read an excel file that has date columns with the below code
src1_df = pd.read_excel("src_file1.xlsx", keep_default_na = False)
Even though I have specified, keep_default_na = False, I see that the data frame has 'NaT' value(s) for corresponding blank cells in Excel date columns.
Please suggest, how to get a blank string instead of 'NaT' while parsing Excel files.
I am using Python 3.x and Pandas 0.23.4
src1_df = pd.read_excel("src_file1.xlsx", na_filter=False)
Then you will have empty string ("") as "na" value
In my case I read excel per line and replace "" and "NaT" to None:
for line in src1_df.values:
for index, value in enumerate(line):
if value == '' or isinstance(value, pd._libs.tslibs.nattype.NaTType):
line[index] = None
dostuff_with(line)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.