BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Precision for a particular column in a data frame export to csv

Hello,

I am interested in formatting a particular column in a data frame, but am unsure as to how to go about doing so. The pandas documentation has a float_format argument for pandas.DataFrame.to_csv, but I don’t want to format all floats in this format, just one where I need like 8 decimals because I am dealing with very small numbers and precision is important.

The line of code I’m looking to modify is

filtered_res[filtered_res.keys()[:-1]].to_csv(’…/Processed/’ + i+".csv")

So if I have a column p_sim, how can I get something like .005 to display as .004994983211182?

Thank you,
Justin

It would be helpful if you could share a sample file. It helps people experiment and get to a solution.

If the value is 0.004994983211182, I expect it to be written to the CSV file. Is it not the case for you?

If you want to have only a few of the values with such precision, then you can transform the column into a string type and modify those values specifically before exporting.