How to delete an element in python

Asked

Viewed 47 times

-3

I have a database.

created a variable and assigns values from a column to it x1 = dataobitos.SEXO

there are three distinct values: "F", "M", "Undefined".

I need to eliminate "Indefinite," but I can’t.

have tried:

x2 = x1.drop("indefinido")
x2 = x1.remove("SEXO", "indefinido")
x2 = x1.remove("indefinido")

but nothing works out... Putz...

I’m starting now with this science.

  • You need to explain your problem better. What data structure are you using? An array, list, dataframe? Are you reading this data from a database? What type of database? Do you want to remove only after reading or want to erase them from the database?

  • hehehe. sorry. is a dataframe, excel. did not want to remove from bd, just create a variable without a specific value. in the "sex" column I have only 3 possible values, ’m', f' and indefinite. I wanted to put only’m and f in a variable to perform operations.

1 answer

0

What you can do is filter the unwanted lines from the dataframe using Loc and then select only the desired column:

df_filtrado = df.loc[df['SEXO'] != 'Indefinido']
coluna_sexo = df_filtrado['SEXO']

Browser other questions tagged

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