0

I tried to filter my data with pandas but I have not succeeded, I changed my data to a .csv file and did the following:

import pandas as pd 
data = pd.read_csv("test3.csv") 
print (type(data))
print(data)

By doing this I get my table:

    C1   C2   C3   C4   C5
0  1.0  2.0  3.0  4.0  5.0
1  2.0  3.0  4.0  5.0  6.0
2  3.0  4.0  5.0  6.0  7.0
3  4.0  5.0  6.0  7.0  8.0

class 'pandas.core.frame.DataFrame'

Now I need that for the rows in which the columns meet a condition, python prints that row for example the rows for which all the columns are <4.0, the idea is that I have a condition for each column. I tried this but it does not work:

for item in data: 
    fil_C1=(data["C1"]) == 4.0
    print (fil_C1)

please help me!!!

1 Answers1

0

If you need to retain rows where columns value for C1 is less than 4, try the following:

less_than_4 = data[data['C1'] < 4]
print(less_than_4)

If you have multiple conditions say C1 less than 4 and C5 greater than 5 try this:

mul_conditions = data[(data['C1'] < 4) & (data['C5'] > 5)]
print(mul_conditions)

Let me know how it goes.

Sagar Dawda
  • 1,126
  • 9
  • 17