小编Lxn*_*ndr的帖子

Pandas 遍历 DataFrame 行对

如何遍历 Pandas DataFrame 的成对行?

例如:

content = [(1,2,[1,3]),(3,4,[2,4]),(5,6,[6,9]),(7,8,[9,10])]
df = pd.DataFrame( content, columns=["a","b","interval"])
print df
Run Code Online (Sandbox Code Playgroud)

输出:

   a  b interval
0  1  2   [1, 3]
1  3  4   [2, 4]
2  5  6   [6, 9]
3  7  8  [9, 10]
Run Code Online (Sandbox Code Playgroud)

现在我想做类似的事情

for (indx1,row1), (indx2,row2) in df.?
    print "row1:\n", row1
    print "row2:\n", row2
    print "\n"
Run Code Online (Sandbox Code Playgroud)

哪个应该输出

row1:
a    1
b    2
interval    [1,3]
Name: 0, dtype: int64
row2:
a    3
b    4
interval    [2,4]
Name: 1, dtype: int64

row1:
a    3
b …
Run Code Online (Sandbox Code Playgroud)

python loops dataframe pandas

3
推荐指数
2
解决办法
6987
查看次数

标签 统计

dataframe ×1

loops ×1

pandas ×1

python ×1