Hello I have several TXT files with CPF numbers. The CPF has 11 numbers, so you can have leading zeros to complete that size I opened these files in Excel and put them together into one. In the CPF column, before opening each file, I made the Excel import command to Text to keep the zeros. In xlsx format worked out
But when I recorded as CSV I saw that the left zeros are gone
In Python 3 I opened, to use pandas later, and I saw that it actually lost the zero on the left and turned int64:
candidatos = pd.read_csv("candidatos_excel_cpfinteiro_csv.csv",sep=';',encoding = 'latin_1')
candidatos.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 26245 entries, 0 to 26244
Data columns (total 9 columns):
UF 26245 non-null object
Estado 26245 non-null object
Cargo 26245 non-null object
Nome_completo 26245 non-null object
CPF 26245 non-null int64
Nome_urna 26245 non-null object
Partido 26245 non-null object
Partido_completo 26245 non-null object
Situacao 26245 non-null object
dtypes: int64(1), object(8)
memory usage: 1.0+ MB
I tried to open the Excel file directly with xlrd, but it stayed as number in the same way:
xlsx = pd.ExcelFile('candidatos_excel_cpfinteiro.xlsx')
candidatos = pd.read_excel(xlsx, 'Planilha1')
candidatos.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 26245 entries, 0 to 26244
Data columns (total 9 columns):
UF 26245 non-null object
Estado 26245 non-null object
Cargo 26245 non-null object
Nome_completo 26245 non-null object
CPF 26245 non-null int64
Nome_urna 26245 non-null object
Partido 26245 non-null object
Partido_completo 26245 non-null object
Situacao 26245 non-null object
dtypes: int64(1), object(8)
memory usage: 1.0+ MB
Please, would anyone have a suggestion of how to keep the zeros to the left? Or keep this column as a string?