如何遍历 DataFrame
中的行?出于某种原因,iterrows()
返回元组而不是 Series
。我也明白这不是使用 Pandas 的有效方式。
最佳答案
使用:
s = pd.Series([0,1,2])
for i in s:
print (i)
0
1
2
数据框
:
df = pd.DataFrame({'a':[0,1,2], 'b':[4,5,8]})
print (df)
a b
0 0 4
1 1 5
2 2 8
for i,s in df.iterrows():
print (s)
a 0
b 4
Name: 0, dtype: int64
a 1
b 5
Name: 1, dtype: int64
a 2
b 8
Name: 2, dtype: int64
关于loops - 如何在 Pandas 中将 DataFrame 的行迭代为系列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39333099/