
在Pandas中实现遍历 DataFrame 行的方法
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本文介绍了如何使用Python的Pandas库高效地遍历DataFrame中的每一行数据,并提供了多种实用方法以供读者参考和实践。
有如下 Pandas DataFrame:
```python
import pandas as pd
inp = [{ c1: 10, c2: 100 }, { c1: 11, c2: 110 }, { c1: 12, c2: 120 }]
df = pd.DataFrame(inp)
print(df)
```
上面代码输出:
```
c1 c2
0 10 100
1 11 110
2 12 120
```
现在需要遍历上述 DataFrame 的每一行。对于每一行,都希望能够通过列名访问对应的元素(单元格中的值)。也就是说,希望实现类似以下的功能:
```python
for row in df.iterrows():
print(row[1][c1])
```
全部评论 (0)
还没有任何评论哟~


