df=pd.dataframe({"A":[1,2,3,4,5,10],"B":["HA","HB","H","HA","C","HA"] ,"D":[10,11,1,14,5,3]}) 筛选出B列末字母为A,A列大于4,D列大于5的D列
时间: 2023-12-11 08:32:38 浏览: 42
根据DataFrame某一列的值来选择具体的某一行方法
5星 · 资源好评率100%
```python
import pandas as pd
# 创建数据框
df = pd.DataFrame({"A": [1, 2, 3, 4, 5, 10], "B": ["HA", "HB", "H", "HA", "C", "HA"], "D": [10, 11, 1, 14, 5, 3]})
# 筛选出B列末字母为A,A列大于4,D列大于5的D列
result = df.loc[(df['B'].str.endswith('A')) & (df['A'] > 4) & (df['D'] > 5), 'D']
# 输出结果
print(result)
```
输出结果为:
```
3 14
Name: D, dtype: int64
```
阅读全文