简体   繁体   中英

how to go to particular column in csv file and print the whole row if in column value is less than particular value

I have a csv file which contains 4 rows and 26 columns. I need to go to 22 column and if the values in that column are less than 0.5, I need to grep the whole row of that particular value using python

the code which i tried

df=pd.read_csv("trial.txt",delimiter='\\t')

a=df[df['col_22'] < 0.5]

print a

**but when i am executing the code the value of the 1 and last column of that row are only printing but not values of the other columns of that row,but i want to print the all 26 column values of that row in a txt file **

import pandas as pd
df=pd.read_csv('your csv file path')

df.loc[df.col_22 < 0.5]

Example

import pandas as pd
df = pd.DataFrame({'name':['john','anna','goli'],
    'age':[34,27,45]})
print(df.loc[df.age==45])

Output:

  name  age
2  goli   45

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM