Search code examples
python-3.xdataframecsvexport-to-csv

Writing floats into a csv file but floats become a string


I am writing a dataframe into a csv as follows:

appended_Dimension.to_csv("outputDimension.csv")

The dataframe is as follows:

     Cameroun    Rwanda     Niger    Zambia      Mali    Angola  Ethiopia  
ECON  0.056983  0.064422  0.047602  0.070119  0.048395  0.059233  0.085559   
FOOD  0.058250  0.046348  0.048849  0.043527  0.049064  0.013157  0.081436   
ENV   0.013906  0.004013  0.010519  0.001973  0.005360  0.023010  0.008469   
HEA   0.041496  0.078403  0.040154  0.054466  0.029954  0.053007  0.061761   
PERS  0.056687  0.021978  0.062655  0.056477  0.087056  0.089886  0.043747 

The output is as follows:

enter image description here

I d like to write data in a float format so i can process it in csv directly. How can i do that please?


Solution

  • You cannot keep it as float inside the csv. The csv will treat everything as strings. You must load your data from the csv and perform the relevant operations then save it back. You cannot manipulate it while it is present inside the csv.