python pandas dataframe 多个变量的筛选

来源:互联网 发布:闪讯网络电缆没有连接 编辑:程序博客网 时间:2024/05/21 09:27

参考文件:

https://mp.weixin.qq.com/s/YeJ3pnq2JKEKbGu4L-4uRw

多个变量的筛选:

import pandas as pdiris = pd.read_excel(r'C:\Users\lhh\Desktop\zlp\iris.xlsx')#选择一个变量print(iris.loc[iris.Species=='setosa'])#选择两个变量,# 需要注意的是:多个变量的筛选,可以是或(|)关系、可以是且(&)关系还可以是非(~)关系,一定要用圆括号把条件括起来。#['Sepal.Length','Species'] 选定指定的列print(iris.loc[(iris.Species=='setosa')& (iris['Sepal.Width'] >= 3.2),['Sepal.Length','Species']])
   Sepal.Length  Sepal.Width  Petal.Length  Petal.Width Species0           5.1          3.5           1.4          0.2  setosa1           4.9          3.0           1.4          0.2  setosa2           4.7          3.2           1.3          0.2  setosa3           4.6          3.1           1.5          0.2  setosa4           5.0          3.6           1.4          0.2  setosa   Sepal.Length Species0           5.1  setosa2           4.7  setosa4           5.0  setosa





原创粉丝点击