How filter multiple column with the same condition?

MauriAndres

I'm trying to manipulate a DataFrame with 8 columns and 263.000 rows.

This is how to look my DF:

ID1          ID2         dN          dS          t           Label_ID1   Label_ID2   Group
QJY77946     NP_073551   0.0241      0.1402      0.1479      229E-CoV    229E-CoV    Intra
QJY77954     NP_073551   0.0119      0.0912      0.0870      229E-CoV    229E-CoV    Intra
QJY77954     QJY77946    0.0119      0.0439      0.0566      229E-CoV    229E-CoV    Intra
QJY77962     NP_073551   0.0119      0.0912      0.0870      229E-CoV    229E-CoV    Intra
QJY77962     QJY77946    0.0119      0.0439      0.0566      229E-CoV    229E-CoV    Intra

My goal is filter all the values <= 6 in the columns "dN", "dS" and "t". To make this I filter the rows when the values in any columns select (dN, dS and t) have a value <= 6.

df_1_S = pd.read_csv("S_YN00.csv",sep="\t", names=['ID1',"ID2","dN","dS","t","Label_ID1","Label_ID2","Group"])

S_greather_than = (df_1_S["dN"] < 6)

df_1_S.loc[S_greather_than]

This it works, but when I trying add more columns (dS and t):

S_greather_than = (df_1_S["dN"] < 6) & (df_1_S["dS"] < 6) & (df_1_S["t"] < 6)

df_1_S.loc[S_greather_than] 

different method: using or ( | ) 

S_greather_than = ((df_1_S["dN"] < 6) | (df_1_S["dS"] < 5) | (df_1_S["t"] < 6))

df_1_S.loc[S_greather_than] 

Happens this error:

TypeError: '<' not supported between instances of 'str' and 'int'

I understand the problem but I don´t know how filter the rows with values <= 6 at the same time.

Any idea or help is welcome.

Thank!

Ishwar Venugopal

Change data type of column 'dS' to float as follows:

df_1_S['dS'] = df_1_S['dS'].astype(float)

The error you are getting is probably because 'dS' column is of type 'object' as mentioned in the comments.

Your code should work fine with this change.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to apply multiple condition in same column in excel

From Dev

Multiple Filter in the same column

From Dev

How to create independent filter for each column with same condition in excel?

From Dev

Multiple SQL filter on same column

From Dev

joint result for multiple condition on same column

From Dev

Slice string in multiple column with same condition

From Dev

Slice string in multiple column with same condition

From Dev

Multiple ordering on same column with different condition

From Dev

How to update multiple rows of multiple columns with single value having same condition for every column

From Dev

how to add multiple filter condition in array of object?

From Dev

If Condition is same then how to update multiple query in php

From Dev

how to select multiple same column in one column

From Dev

How to filter dataframe with same column name?

From Dev

SQL query to implement multiple WHERE condition on same column

From Dev

to write a select query which strictly satisfies a multiple condition on same column

From Dev

Create a new column in pandas based on values in multiple columns and the same condition

From Dev

How to filter Table row with multiple condition .ie on checkbox selection show respected row. each checkbox represent Column and row value

From Dev

Gremlin : Multiple filter condition "OR"

From Dev

Multiple condition filter in AngularJS

From Java

Filter df based on multiple column values of other columns in the same df

From Dev

how do i filter a column with multiple values

From Dev

How to apply multiple column filter(String) in python

From Dev

How to filter measure in the Filter function by multiple items from the same hierarchy

From Dev

How to filter measure in the Filter function by multiple items from the same hierarchy

From Dev

How to add multiple numbers with the same name in the column?

From Dev

How to add multiple numbers with the same name in the column?

From Dev

How can I filter relationship condition for multiple iteration specified with Cypher?

From Dev

How to filter with multiple condition text input in Ag-Grid?

From Dev

Filter for rows with column condition on an array

Related Related

  1. 1

    How to apply multiple condition in same column in excel

  2. 2

    Multiple Filter in the same column

  3. 3

    How to create independent filter for each column with same condition in excel?

  4. 4

    Multiple SQL filter on same column

  5. 5

    joint result for multiple condition on same column

  6. 6

    Slice string in multiple column with same condition

  7. 7

    Slice string in multiple column with same condition

  8. 8

    Multiple ordering on same column with different condition

  9. 9

    How to update multiple rows of multiple columns with single value having same condition for every column

  10. 10

    how to add multiple filter condition in array of object?

  11. 11

    If Condition is same then how to update multiple query in php

  12. 12

    how to select multiple same column in one column

  13. 13

    How to filter dataframe with same column name?

  14. 14

    SQL query to implement multiple WHERE condition on same column

  15. 15

    to write a select query which strictly satisfies a multiple condition on same column

  16. 16

    Create a new column in pandas based on values in multiple columns and the same condition

  17. 17

    How to filter Table row with multiple condition .ie on checkbox selection show respected row. each checkbox represent Column and row value

  18. 18

    Gremlin : Multiple filter condition "OR"

  19. 19

    Multiple condition filter in AngularJS

  20. 20

    Filter df based on multiple column values of other columns in the same df

  21. 21

    how do i filter a column with multiple values

  22. 22

    How to apply multiple column filter(String) in python

  23. 23

    How to filter measure in the Filter function by multiple items from the same hierarchy

  24. 24

    How to filter measure in the Filter function by multiple items from the same hierarchy

  25. 25

    How to add multiple numbers with the same name in the column?

  26. 26

    How to add multiple numbers with the same name in the column?

  27. 27

    How can I filter relationship condition for multiple iteration specified with Cypher?

  28. 28

    How to filter with multiple condition text input in Ag-Grid?

  29. 29

    Filter for rows with column condition on an array

HotTag

Archive