Pandas 过滤数据帧时返回相同的初始输入';价值观
我从read_html pandas属性中获得了以下数据帧Pandas 过滤数据帧时返回相同的初始输入';价值观,pandas,Pandas,我从read_html pandas属性中获得了以下数据帧 A 1.48 2.64 1.02 2.46 2.73 B 658.4 14.33 7.41 15.35 8.59 C 3.76 2.07 4.61 2.26 2.05 D 513854.86 5.70 0.00 5.35 30.16
A 1.48 2.64 1.02 2.46 2.73
B 658.4 14.33 7.41 15.35 8.59
C 3.76 2.07 4.61 2.26 2.05
D 513854.86 5.70 0.00 5.35 30.16
我想删除超过150的行,所以我做了一个df1=df[df>150]
,但是它返回相同的表
然后我想在routeroute=pd.read_html(https//route,decimal=')中包含小数
并继续返回相同的初始数据帧,而不使用过滤器
这将是我想要的输出:
A 1.48 2.64 1.02 2.46 2.73
C 3.76 2.07 4.61 2.26 2.05
需要:
或:
然后比较-获取布尔数据帧:
print (df.iloc[:, 1:] > 150)
1 2 3 4 5
0 False False False False False
1 True False False False False
2 False False False False False
3 True False False False False
print (df.iloc[:, 1:] <= 150)
1 2 3 4 5
0 True True True True True
1 False True True True True
2 True True True True True
3 False True True True True
最后一个第一个
系列
用~
反转并过滤。Hi@jezrael非常感谢您的帮助!我面临的问题是,当我尝试df.iloc[:,1:]>150
时,所有的列都是正确的,你认为我能做些什么来克服这个问题?高兴可以帮助;)天气真好!
df1 = df[(df.iloc[:, 1:] <= 150).all(1)]
print (df1)
0 1 2 3 4 5
0 A 1.48 2.64 1.02 2.46 2.73
2 C 3.76 2.07 4.61 2.26 2.05
print (df.iloc[:, 1:])
1 2 3 4 5
0 1.48 2.64 1.02 2.46 2.73
1 658.40 14.33 7.41 15.35 8.59
2 3.76 2.07 4.61 2.26 2.05
3 513854.86 5.70 0.00 5.35 30.16
print (df.iloc[:, 1:] > 150)
1 2 3 4 5
0 False False False False False
1 True False False False False
2 False False False False False
3 True False False False False
print (df.iloc[:, 1:] <= 150)
1 2 3 4 5
0 True True True True True
1 False True True True True
2 True True True True True
3 False True True True True
print ((df.iloc[:, 1:] > 150).any(1))
0 False
1 True
2 False
3 True
dtype: bool
print ((df.iloc[:, 1:] <= 150).all(1))
0 True
1 False
2 True
3 False
dtype: bool