Delete lines from a Dataframe from a list of python strings

Asked

Viewed 49 times

0

I am with A Dataframe for analysis of Covid-19 and When I pull the largest amount of cases or deaths, return me to the continents and I would like to delete only the entries where the continents appear, leave only the countries.

For example, I created this list and then I was able to pull the inputs without the continents.

continentes = ['Europe', 'Asia', 'North America', 'South America', 'Oceania', 'Africa', 'European Union']

df.loc[~df.location.isin(continentes)][df.date == '2021-04-27'].sort_values(by='total_cases', ascending=False)

However, when I will create a bar chart and use this command

df.loc[df.date == '2021-04-27', ['location', 'total_deaths']].sort_values(by="total_deaths", ascending=False)[0:6]

It is returned the values of the continents, so I would like to delete these entries, some commands that I tried not solved or gave error, for example:

df.drop(df[df.location == 'Europe', 'North America', 'Asia', 'Oceania', 'South America', 'Africa', 'European Union'].index)

df.drop(df[df.location == continentes].index)

I will try to reproduce when I give the command to locate the countries with the most deaths and their location

location        total_deaths        

world           3134956.0
europe          1007023.0
north america   843246.0
european union  682014.0
south america   658283.0

I really appreciate it if someone can help me!!!

  • Can you update the post with a piece of your dataframe so we can reproduce the problem? In time, do not paste the image.

  • updated the post, need to be a representation of the whole dataframe? or just that enough? because it is a dataframe with 59 columns kkkkkkk very large

  • 1

    I believe that solves: df = df.drop(df[df['location'].isin(continentes)].index)

  • Thanks!! Thanks a lot Paul

No answers

Browser other questions tagged

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