I am trying to read data from excel using pandas.ExcelFile() into a dataframe, and then outputting a text file using to_csv.
This output text file should be at precision of 20 decimal places and rounded to 20 decimal places.
If an input value in excel is .005, my code converts it to 0.0050000000000000001 which is incorrect because of the very last digit. It should be 0.0050000000000000000
Here's my code:
dataFrame = pd.ExcelFile("xlFile.xlsx")
pd.set_option("display.precision", 20)
dataFrame.ColumnToRound = dataFrame.ColumnToRound.round(20)
dataFrame.to_csv("out.txt", index=False, sep='\t', float_format='%.20f')
The INPUT excel file would look like this (just one column and one value for simplicity):
ColumnToRound
.005
I have tried using the kwarg float_precision='round_trip' when reading the excel file using pandas.ExcelFile(), but it did not make a difference.
Side note: yes, I know 20 decimal places is a lot and probably more than necessary, but it was not my decision. It has to be 20 decimal places.