2021年3月24日星期三

How to filter out pandas dataframe rows based on contains condition?

I have below dataframe

df = pd.DataFrame({'vals': [1, 2, 3, 4, 5], 'ids': ['News: Latest', 'News', 'Cricket', 'Football', 'Football Match: India']})  print(df)       vals                    ids  0     1           News: Latest  1     2                   News  2     3                Cricket  3     4               Football  4     5  Football Match: India  

I have input array, by which i wanted to check df and filter out corresponding data.

valueToFilter = ["News", "India"]  

Output i want

   vals                    ids  0     1           News: Latest  1     2                   News  2     5  Football Match: India  

Can anyone guide me how can i achieve this ?

https://stackoverflow.com/questions/66792887/how-to-filter-out-pandas-dataframe-rows-based-on-contains-condition March 25, 2021 at 11:59AM

没有评论:

发表评论