1

I'm reading a csv file like this:

import pandas as pd

arq_pedido = pd.read_csv('Pedido.csv',delimiter=";", encoding = "ISO-8859-1")

I have a ID column (this column is supposed to be an INT column, but in Brazil (Portuguese), thousand's numbers is represented like this: 1.000 instead of 1000. So, my ID column is dfloat64 at the moment.

I have one ID who is 1.908 (1908), and this number shows 1.9080000000000001. How can I transform dfloat64 to int? Or, how can I replace dots (.) for comma (,), to turned that numbers in thousands ones?

Him
  • 5,257
  • 3
  • 26
  • 83

2 Answers2

2

There is a thousands parameter for this. Try,

arq_pedido = pd.read_csv('Pedido.csv', delimiter=";", encoding = "ISO-8859-1", thousands=".")

You may also wish to set decimal="," to handle decimal numbers correcltly.

James Elderfield
  • 2,389
  • 1
  • 34
  • 39
0

The read_csv method has parameters for just about every conceivable scenario. You're probably interested in the thousands parameter for the thousands place separator, the decimal parameter for the decimal point, and the sep parameter for the column separator.

import pandas as pd
import io
foobar = io.StringIO("foo;bar \n 1,000; 2.0")
pd.read_csv(foobar, thousands=",", decimal=".", sep=";")
#    foo  bar 
#0  1000   2.0
Him
  • 5,257
  • 3
  • 26
  • 83