问题
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
回答1:
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)
来源:https://stackoverflow.com/questions/53304800/pandas-read-excel-parses-date-columns-with-blank-values-to-nat