0

In Python 3 and pandas I have a dataframe with a column of codes. The column "cnpj"

segura.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 35581 entries, 0 to 35580
Data columns (total 3 columns):
cnpj            35581 non-null object
nome_empresa    35581 non-null object
estado          35581 non-null object
dtypes: object(3)
memory usage: 834.0+ KB

This column always has 14 digits. Example: "00529528000152" and "02197190000104"

Please, can I create a new column that has the first eight digits of column "cnpj" in its rows? Example: "00529528" and "02197190"

Reinaldo Chaves
  • 965
  • 4
  • 16
  • 43

1 Answers1

2

Try:

segura['NEW_ID'] = segura['cnpj'].str[:8]
Keith Dowd
  • 631
  • 4
  • 10