dataframe按照行来遍历
时间: 2023-06-29 09:17:54 浏览: 101
对Python中DataFrame按照行遍历的方法
可以使用`iterrows()`方法来按照行来遍历DataFrame。示例代码如下:
```python
import pandas as pd
# 创建DataFrame
df = pd.DataFrame({'name': ['Alice', 'Bob', 'Charlie'], 'age': [25, 30, 35]})
# 按照行遍历DataFrame
for index, row in df.iterrows():
print(f"Name: {row['name']}, Age: {row['age']}")
```
输出结果:
```
Name: Alice, Age: 25
Name: Bob, Age: 30
Name: Charlie, Age: 35
```
阅读全文