string treatment in pandas

2

Good Night Sirs, I have the following Dataframe, imported from an xlsx.

    NUM_LEGISLACAO  DSC_URL  COD_SITUACAO  ...    DSC_TIPO     num   ano
264    89.272/1984      NaN           2.0  ...   NORMATIVO  89.272  1984
265    90.396/1984      NaN          11.0  ...   NORMATIVO  90.396  1984
266    90.804/1985      NaN           2.0  ...    CONCRETO  90.804  1985
267     81195/1978      NaN           NaN  ...         NaN   81195  1978
268      5475/1905      NaN           NaN  ...         NaN   05475  1905
269    90.396/1984      NaN          11.0  ...   NORMATIVO  90.396-A  1984

Imported with the code below:

df1 = pd.read_excel(file01, sheet_name='Exportar Planilha')
df1['num'], df1['ano'] = df1['NUM_LEGISLACAO'].str.split('/').str

#notok
#substitui '.' e '-' no campo 'num'
df1['num'] = df1.num.str.replace('[\.-]', '')

#formata com 5 digitos
df1.num = df1.num.astype(str).str.rjust(5, '0')
df1['num'] = df1.num.astype(str).str.zfill(5)

I want to remove '.' of the 'num' field, and produce the following result:

    NUM_LEGISLACAO  DSC_URL  COD_SITUACAO  ...    DSC_TIPO     num   ano
264    89.272/1984      NaN           2.0  ...   NORMATIVO  89272  1984
265    90.396/1984      NaN          11.0  ...   NORMATIVO  90396  1984
269    90.396/1984      NaN          11.0  ...   NORMATIVO  90396A  1984

However, my code does not work and displays the following error:

  

TypeError: Type aliases can not be used with isinstance ().

    
asked by anonymous 15.06.2018 / 17:58

1 answer

0

I found the reason for the failure in this post link . Due to a bug in Python 3.5.2 and earlier, the error happens.

My environment is a Linux Ubuntu, which does not bring update to this version of python, so to solve, I installed an Anaconda environment, which comes with several Python versions available.

Details on link

    
17.06.2018 / 13:32