简体   繁体   中英

Sorting and filtering dataframes in Pandas Python

在此处输入图像描述

That is my df

I want to sort the predictors_frame byt the Coef column, and filter by Pvalue < 0.05, but I am getting an error when I try to do it, i believe the syntax is incorrect. This is what I have so far.

predictors_frame = predictors_frame.sort_values(['Coef']), predictors_frame[predictors_frame['Pvalue']<.05]

The sorting is working properly but the filtering is what I have wrong. Is giving me the and AttributeEttor: 'tuple' object has no attribute 'head'

df = pd.DataFrame({"ali":[4,5,3,4,5,8,7],"mali":[1,10,2,4,6,6,7]})

# output
   ali  mali
0   4   1
1   5   10
2   3   2
3   4   4
4   5   6
5   8   6
6   7   7

df[df.mali<5].sort_values(by="ali") # you could reset your index here also.

#output
   ali  mali
2   3   2
0   4   1
3   4   4

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