2
I want to change the type of a column of a CSV file. I used this command:
cand_doacoes['CPF_CNPJ_doador'] = cand_doacoes.CPF_CNPJ_doador.astype(int64)
But the error appears:
NameError Traceback (most recent call last)
<ipython-input-33-842f431fca9e> in <module>()
----> 1 cand_doacoes['CPF_CNPJ_doador'] = cand_doacoes.CPF_CNPJ_doador.astype(int64)
NameError: name 'int64' is not defined
Someone knows the right command?
Thank you. It really worked But it gave this error after: Valueerror: Cannot Convert non-finite values (NA or inf) to integer I think that’s why in this column there are blank lines. I cannot delete these lines. Is the solution to convert the blank lines to "0"? Or is there some other command?
– Reinaldo Chaves
I’ll run some tests here and then give feedback.
– Paulo C
The values of the Cpf_cnpj_donor column are only numbers, without the points?
– Paulo C
If the column contains only numbers, vc could loop before the conversion by filling the empty cells with '0', thus: cand_doacoes['Cpf_cnpj_doador'] = [x if x.isdigit() Else '0' for x in cand_doacoes.Cpf_cnpj_doador]
– Paulo C