错误:尝试在数据框架中的两列上进行迭代时,要解压的值太多(预期为2) [英] Error:-too many values to unpack (expected 2), while trying to iterate over two columns in a Data Frame

查看:74
本文介绍了错误:尝试在数据框架中的两列上进行迭代时,要解压的值太多(预期为2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for L,M in laundry1['latitude'],laundry1['longitude']:
    print('latitude:-')
    print(L)
    print('longitude:-')
    print(M)

我正在尝试遍历数据帧的两列,将值赋给L& M并在其中打印值,但它显示数据集的错误错误,无法解包(预期为2)的值太多",带有错误视图->

i am trying to iterate over the two columns of a data-frame, assigning there value to L & M and printing there value but it shows error of "too many values to unpack (expected 2) " view of the dataset with error view ->enter image description here

示例输出:

纬度:-

22.1449787

22.1449787

18.922290399999998

18.922290399999998

22.1544736

22.1544736

22.136872

22.136872

22.173595499999998

22.173595499999998

经度:-

-101.0056829

-101.0056829

-99.234332

-99.234332

-100.98580909999998

-100.98580909999998

-100.9345736

-100.9345736

-100.9946027

-100.9946027

推荐答案

使用 zip :

for L,M in zip(laundry1['latitude'],laundry1['longitude']):
    print('latitude:-')
    print(L)
    print('longitude:-')
    print(M)

这篇关于错误:尝试在数据框架中的两列上进行迭代时,要解压的值太多(预期为2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆