如何使用循环在 Dataframe
中逐行读取并返回每个值或弹出每个值?
示例:
id name
1 abc
2 vbs
2 askj
最佳答案
假设您正在使用pandas数据框
您可以使用iterrows
In [3]: for index, row in df.iterrows():
...: print('Index is: {}'.format(index))
...: print('ID is: {}; Name is: {}'.format(row['id'], row['name']))
...:
Index is: 0
ID is: 1; Name is: abc
Index is: 1
ID is: 1; Name is: vbs
Index is: 2
ID is: 2; Name is: askj
Iterrows 正在迭代索引、行元组。这里的行是 Series .
In [4]: type(row)
Out[4]: pandas.core.series.Series
关于python - 如何使用循环在数据帧中逐行读取并返回每个值或弹出每个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29799179/