Filtering all rows based on a specific value in Pandas dataframe

user3447653

I have a dataframe that has "yes" when a condition is satisfied and "no" when it is not. Now, I would like to retrieve all the rows that has "No" in it.

I tried with this code:

 df2 = df[df['Logs'].astype(str).str.contains('No')] 
 df3 = df[df['Jobs'].astype(str).str.contains('No')] 
 df4 = df[df['Performance'].astype(str).str.contains('No')] 
 df5 = df2 | df3 | df4

I got the error "unsupported operand types".

For example:

 MachineName    Logs   Jobs   Performance
 121            Yes    No      Yes
 122            Yes    Yes     Yes
 123            Yes    No      No
 125            Yes    Yes     Yes
 126            No     No      No

Output:

 MachineName    Logs   Jobs   Performance
 121            Yes    No      Yes
 123            Yes    No      No
 126            No     No      No
root

Do an equality check on all columns you want to be 'No', and then use any to get a Boolean array.

condition = (df[['Logs', 'Jobs', 'Performance']] == 'No').any(axis=1)
df2 = df[condition]

The resulting output is as expected:

   MachineName Logs Jobs Performance
0          121  Yes   No         Yes
2          123  Yes   No          No
4          126   No   No          No

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Filtering all rows based on one value

From Dev

Filter pandas dataframe based on a column: keep all rows if a value is that column

From Dev

Divide all rows in a pandas dataframe by a specific row

From Dev

Filtering pandas dataframe for all rows where index is consecutive +/-1

From Dev

Drop rows in pandas dataframe based on columns value

From Dev

Repeat rows in a pandas DataFrame based on column value

From Dev

Select all the rows based on a column value pandas

From Dev

Select all the rows based on a column value pandas

From Dev

Extracting all rows from pandas Dataframe that have certain value in a specific column

From Dev

Combining rows on a Dataframe based on a specific column value and add other values

From Dev

MySQL get all rows based on a specific column value (filter by column)

From Dev

How to add a column to a dataframe and set all rows to a specific value

From Dev

Filtering all rows with NaT in a column in Dataframe python

From Dev

Drop rows if value in a specific column is not an integer in pandas dataframe

From Dev

Update Specific Pandas Rows with Value from Different Dataframe

From Dev

Delete certain rows in pandas dataframe with specific datetime value

From Dev

Filtering pandas dataframe rows by contains str

From Dev

Filtering a Pandas DataFrame Without Removing Rows

From Dev

filtering, averaging and removing rows in pandas dataframe

From Java

Dropping rows from pandas dataframe based on value in column(s)

From Dev

Deleting DataFrame rows in Pandas based on column value - multiple values to remove

From Dev

pandas dataframe: how to aggregate a subset of rows based on value of a column

From Dev

How to replicate rows based on value of a column in same pandas dataframe

From Dev

Pandas dataframe remove rows based on index and column value

From Dev

pandas replace specific string with numeric value in a new column for all rows

From Dev

How to explode pandas dataframe based on number value in a specific column

From Dev

Pandas DataFrame filtering based on second column

From Dev

Pandas DataFrame filtering based on second column

From Dev

Pandas dataframe filtering based on group counts

Related Related

  1. 1

    Filtering all rows based on one value

  2. 2

    Filter pandas dataframe based on a column: keep all rows if a value is that column

  3. 3

    Divide all rows in a pandas dataframe by a specific row

  4. 4

    Filtering pandas dataframe for all rows where index is consecutive +/-1

  5. 5

    Drop rows in pandas dataframe based on columns value

  6. 6

    Repeat rows in a pandas DataFrame based on column value

  7. 7

    Select all the rows based on a column value pandas

  8. 8

    Select all the rows based on a column value pandas

  9. 9

    Extracting all rows from pandas Dataframe that have certain value in a specific column

  10. 10

    Combining rows on a Dataframe based on a specific column value and add other values

  11. 11

    MySQL get all rows based on a specific column value (filter by column)

  12. 12

    How to add a column to a dataframe and set all rows to a specific value

  13. 13

    Filtering all rows with NaT in a column in Dataframe python

  14. 14

    Drop rows if value in a specific column is not an integer in pandas dataframe

  15. 15

    Update Specific Pandas Rows with Value from Different Dataframe

  16. 16

    Delete certain rows in pandas dataframe with specific datetime value

  17. 17

    Filtering pandas dataframe rows by contains str

  18. 18

    Filtering a Pandas DataFrame Without Removing Rows

  19. 19

    filtering, averaging and removing rows in pandas dataframe

  20. 20

    Dropping rows from pandas dataframe based on value in column(s)

  21. 21

    Deleting DataFrame rows in Pandas based on column value - multiple values to remove

  22. 22

    pandas dataframe: how to aggregate a subset of rows based on value of a column

  23. 23

    How to replicate rows based on value of a column in same pandas dataframe

  24. 24

    Pandas dataframe remove rows based on index and column value

  25. 25

    pandas replace specific string with numeric value in a new column for all rows

  26. 26

    How to explode pandas dataframe based on number value in a specific column

  27. 27

    Pandas DataFrame filtering based on second column

  28. 28

    Pandas DataFrame filtering based on second column

  29. 29

    Pandas dataframe filtering based on group counts

HotTag

Archive