简体   繁体   中英

How Pass This Error " ValueError: too many values to unpack (expected 2) in Python?


Image

You should use df.iterrows() it is more convenient regarding csv data frame looping. Exemple:

df = pd.DataFrame({'A': [1, 2, 3], 'B': [100, 200, 300]})

for index, row in df.iterrows():
    print(row['A'], row['B'])

Explanation:

When you do not unpack all of the entries in a list, the "valueerror: too many values to unpack (expected 2)" error occurs.

This error is frequently triggered when an attempt is made to iterate through the elements in a dictionary. To resolve this issue, you should itterate over a dictionary using the items()/iterrows() function.

Nota bene: If I were you, I would paste the code + output straight into stackoverflow rather than using a snapshot.

Cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM