python - 如何使用循环在数据帧中逐行读取并返回每个值或弹出每个值

标签 python azure dataframe

如何使用循环在 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/

相关文章:

python - Groupby()和 Pandas 中的聚合

python - 如何在不在 PyCharm 中重新加载包的情况下在 Python 控制台中进行调试?

python - 使用正则表达式在 python 中的字符串中将 Boolean true 转换为 True

python2.7 : Could not import get_url from bottle

python - Tensorflow/TFLearn - 张量 'target/Y:0' 的 ValueError : Cannot feed value of shape (64, ),其形状为 '(?, 1)'

c# - Azure Blob 存储共享访问签名 (SAS) - 签名不匹配

r - 当两列中的值与第二个数据框中的值匹配时对数据框进行子集化

python - 根据另一列中的值从一列中减去

c# - MSAL + Azure 应用服务

Azure DevOps 构建无法加载引用的程序集