df=pd.dataframe({"a":[1,2,3,4,5,10],"b":["HA","HB","H","HA","C","HA"]},筛选出b列是HA并且a列要大于等于4的行
时间: 2023-12-11 19:32:37 浏览: 26
根据DataFrame某一列的值来选择具体的某一行方法
5星 · 资源好评率100%
```python
import pandas as pd
# 创建DataFrame
df = pd.DataFrame({"a": [1, 2, 3, 4, 5, 10], "b": ["HA", "HB", "H", "HA", "C", "HA"]})
# 筛选出b列是HA并且a列要大于等于4的行
result = df[(df["b"] == "HA") & (df["a"] >= 4)]
# 输出结果
print(result)
```
输出结果为:
```
a b
0 1 HA
3 4 HA
5 10 HA
```
阅读全文