How to round up value created in pandas?

1

Hello Please, in Python 3 pandas I am creating this dataframe with the sum of another dataset:

total = cand_doacoes.groupby(['CPF_candidato', 'Nome_candidato', 'Cargo']).Valor.sum().reset_index()

total = total[(total['Cargo'] == 'Deputado Federal')]

total.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 5516 entries, 0 to 19707
Data columns (total 4 columns):
CPF_candidato     5516 non-null int64
Nome_candidato    5516 non-null object
Cargo             5516 non-null object
Valor             5516 non-null object
dtypes: int64(1), object(3)
memory usage: 150.8+ KB

The Value column I wish to round to two decimal places, so I put this command:

total.round({'Valor': 2})

But it did not work:

CPF_candidato Nome_candidato  Cargo   Valor
0 1608657 STEFANO AGUIAR DOS SANTOS   Deputado Federal    10000,00548,501675,00500,00400,003750,0010000,...
1 2498316 HENRIQUE EDUARDO BARROSO MOREIRA    Deputado Federal    240,00124,0025,8699,79285,71245,00
6 7331304 CARLOS MAURO CABRAL BENEVIDES   Deputado Federal    3501,4010000,00100000,00200000,00100000,003000...

Does anyone know how to do it?

    
asked by anonymous 11.10.2017 / 20:19

1 answer

1

ANSWER THAT WORK, FROM LUIZ VIEIRA - already reading the CSV you indicate that the decimal is with ",":

cand_doacoes = pd.read_csv("doacoes_csv.csv",sep=';',encoding = 'latin_1', decimal = ",")

And then groupby worked out:

total = eleitos_d_doadores.groupby(['CPF_candidato', 'Nome_urna', 'Cargo_x']).Valor.sum().reset_index()
    
21.10.2017 / 12:40