How to retrieve data from a dataframe with multiple conditions

Question:

I am trying to extract data from a data frame base on condition.

Dataframe I have

I need to get only values having only fans or the Top 0.10% in the data frame. I am able to get the value using the if condition:-

for i in range(len(dataframe['Display_Name'])):
    if "onlyfans" in dataframe['Description'][i] or "OnlyFans" in dataframe['Display_Name'][i] or "TOP 0.01%" in dataframe['Display_Name'][i] or "top 0.01%" in dataframe['Content'][i]:
        print(dataframe['Display_Name'][i])
        print(dataframe['Description'][i])
        print(dataframe['ID'][i])
        print(i)
        print("*"*25)

but I am getting output like this:-

Shelly d'Inferno @ OnlyFans
Swedish muse/showgirl/ape. #HODLing on for dear life! #GME #AMC to the moon!   
112204991
9
*************************
PSG Kagura
ICI C'EST PARIS   (j'habite dans le sud)  | 2nd @2onlyfansKagura
1340765931887321088
47
*************************
Jack $300 OnlyFans
Data Analyst |
if you ask for context, you're part of the problem |
you don't know who I am |
None of these opinions are my own.
2369480532
52
*************************
OnlyFans
lonely
958973284053286918
55
*************************
cileksu $free onlyfans
24  ücretsiz onlyfans hesabım için linke tıkla⬇️  VIP hesabım için @cileksu8  
1558401021671620608
176
*************************
cileksu $free onlyfans
24  ücretsiz onlyfans hesabım için linke tıkla⬇️  VIP hesabım için @cileksu8  
1558401021671620608
180
*************************
SmashBros OnlyFans
 ‍♂️ ‍♂️ ‍♂️
1422616372408897542
290
*************************

I want a new data frame that I can save into a csv or excel file meeting the above conditions.

Asked By: Lalit Joshi

||

Answers:

filtering = ((dataframe['Description'].str.contains("onlyfans")) | (dataframe['Display_Name'].str.contains("OnlyFans")) | (dataframe['Display_Name'].str.contains("TOP 0.01%")) | (dataframe['Content'].str.contains("top 0.01%")))

dataframe[filtering]

Pandas "or"-operator

Answered By: Tarquinius
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.