Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm aware that you can use df1 = df1[df1['Computer Name'] != 'someNameToBeDropped'] to drop a given string as a row

what if i wanted to do it the other way around. Let's say dropping everything except what i have in a list of strings.

is there a simple hack I haven't noticed?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
226 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this to get rows such that value of col is in that given list

df = df[df[column].isin(list_of_strings)]

Additional to exclude what's in the list

df = df[~df[column].isin(list_of_values)]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...