Skip to content
Advertisement

An addition of non-existing **trailing** zeros at importing csv file by pandas

Importing a .csv file given by

JavaScript

leads to an addition of a trailing zero in the first line. How to avoid it?

enter image description here

Advertisement

Answer

This is just the visual representation of the float data in your df. If you want it different, change the format string for it.

For your numbers '{:,g}' would work (see format specification mini language – scroll down for the table that explains it).

Example:

JavaScript

Output:

JavaScript

From a numerical standpoint there is no difference between 1.4 and 1.40 or 00001.40000000000.


Guarav Kumar’s suggestion to use

JavaScript

is bad advice – it changes the data type for the (single) column to be of type string.

This will prevent you from calculating anything with the numbers of your dataframe.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement