df=pd.dataframe({"a":[1,2,3,4,5,10],"b":["HA","HB","H","A","C","HA"]},筛选出b列第一个字母是H的行
时间: 2023-12-11 18:32:37 浏览: 50
对dataframe进行列相加,行相加的实例
5星 · 资源好评率100%
以下是筛选出b列第一个字母是H的行的代码:
```python
import pandas as pd
# 创建DataFrame
df = pd.DataFrame({"a": [1, 2, 3, 4, 5, 10], "b": ["HA", "HB", "H", "A", "C", "HA"]})
# 筛选出b列第一个字母是H的行
result = df[df['b'].str.startswith('H')]
print(result)
```
输出结果为:
```
a b
0 1 HA
1 2 HB
2 3 H
```
阅读全文