Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the rows which contain a specific words?

I’m using netfilx dataset. uploaded by VICTOR SOEIRO on KAGGLE. I want to make new datasets based on genres . For example, I want new dataframe if genres contain word [‘comedy’] or [‘comedy’,’fantasy’].

My_code
df_comedy = df[df['genres'].str.extract("'comedy'")]

It gives me this error. ValueError: pattern contains no capture groups

Ask me to provide more information, If you don’t understand my question.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you.

>Solution :

Here is Solution for your problem:

import pandas as pd
#reading csv file
df = pd.read_csv("Assignment.csv")

# filtering the rows where Credit-Rating is Fair
df = df[df['Credit-Rating'].str.contains('Fair')]
print(df)

output:

job        Age_Range    Salary    Credit-Rating  Savings    

Own        Middle-aged  High       Fair          10000    
Govt       Young        Low        Fair          15000   
Private    Senior       Average    Fair          20000  
Own        Middle-aged  High       Fair          13000   
Own        oung         Low        Fair          17000  

Use contains instead of extract, you will get your answer.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading