Skip to content
Advertisement

Python pandas: How to extract rows with multiple “exact” certain values

I have a csv file with a lot of data, and I have to print out all the rows that match with multiple conditions, there are 3 columns need to be focused on.

In the ‘description’ columns, I need to find all rows contain six different values and they are ‘Physically active’, ‘Anxiety disorder’, ‘Daily smokers’, ‘Diabetes’, ‘Healthy weight’, and ‘Self-rated health – very good’.

For the ‘group’ column, I need to match with exact word ‘total’, df.group.str.contains doesn’t work because there are also values like ‘total man’.

Also in the ‘population’ column, the word ‘adult’ must be matched too

Sorry it might be confused but I can’t post pictures yet, Please help, thanks.

Advertisement

Answer

df[df.ColumnName == "exact word to match"]

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement