Transform dataframe column into INT - Python 3

Asked

Viewed 450 times

-1

Hello

I have this Dataframe, generated from a file (.txt):

    NUMERO_PROCESSO ANO_PROCESSO    TRIBUNAL
0   0010402         2018            18
1   0010758         2014            01
2   0001622         2012            08
3   0020287         2019            04
4   1001446         2018            02
5   0000795         2019            07
6   1001620         2017            02
7   0001006         2019            11
8   0100584         2017            01
9   0010339         2016            18

The column 'ANO_PROCESSO' is string, as I transform the column of the Dataframe into INT, or as I resolve the issue below without the mentioned errors (generate a Dataframe with lines whose ANO_PROCESSO is greater or equal to 2018):

df_remove = df_contas_validas.loc[(int(df_contas_validas['ANO_PROCESSO']) >= 2018)]

error: cannot Convert the series to

df_remove = df_contas_validas.loc[(df_contas_validas['ANO_PROCESSO'] >= 2018)]

error: '>=' not supported between instances of 'str' and 'int'

1 answer

0

I found the solution to turn the STR column into INT (dataframe):

df_contas_validas['ANO_PROCESSO'] = pd.to_numeric(df_contas_validas['ANO_PROCESSO'])

Now it works:

df_remove = df_contas_validas.loc[(df_contas_validas['ANO_PROCESSO'] >= 2018)]

Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.