Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

python - How can i fix this error: too many values to unpack (expected 4) for the code gievn below?

What is wrong with this code?

import pandas as pd

url1 = 'https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/users.csv'
url2 = 'https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/sessions.csv'
url3 = 'https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/products.csv'
url4 = 'https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/transactions.csv'

lst = [url1, url2, url3, url4]

def read_func(url):
    df = pd.read_csv(url)
    return df

for i in lst:
    users, sessions, products, transcation = read_func(i)

When I run it I get this error:

Traceback (most recent call last):
  File "/main.py", line 15, in <module>
    users, sessions, products, transcation = read_func(i)
ValueError: too many values to unpack (expected 4)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
import pandas as pd
import numpy as np

url1='https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/users.csv'
url2='https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/sessions.csv'
url3='https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/products.csv'
url4='https://raw.githubusercontent.com/ben519/DataWrangling/master/Data/transactions.csv'

lst=[url1, url2, url3, url4]

def read_func(lst):
    dfs = []
    for url in lst:
        dfs.append(pd.read_csv(url))
    return dfs

users, sessions, products, transcation = read_func(lst)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...