I do not see how "Too many values to unpack" Exception applies to my question, if it does please explain
Traceback:
c:\***>python graphJSON.py
Traceback (most recent call last):
File "graphJSON.py", line 17, in <module>
for region, four, one, two, three, threep in rows:
ValueError: too many values to unpack
I'm experiencing the too many values error with this simple peice of code and can't figure out what the issue is: The error comes from the for loop which. I've gotten a message saying this has been asked before however, the answer is totally unclear!
rows = csv.reader(open("graph.csv", "rb"))
# Init the the lists that will store our data
regions = []
fourHrs = []
oneDay = []
twoDay = []
threeDay = []
plusThreeDay = []
# Iterate through all the rows in our CSV
for region, four, one, two, three, threep in rows:
regions = regions + [region]
fourHrs = fourHrs + [four]
oneDay = oneDay + [one]
twoDay = twoDay + [two]
threeDay = threeDay + [three]
plusThreeDay = plusThreeDay + [threep]
# Format the output
output = {"data":[{"Regions":regions},
{"Four Hours":fourHrs},
{"One Day":oneDay},
{"Two Days":twoDay},
{"Three Days":threeDay},
{"More than Three Days":plusThreeDay}
]}
Generate the JSON file json_file = open("graph.json", "w") json.dump(output, json_file) The data in the csv look like:
First 28 25 10 2 7
Second 51 17 8 5 15
Third 38 33 24 7 19
Answered: It turns out the issue was with the CSV, it had more columns at one stage which I deleted, however, I think in excel the reference doesn't get deleted entirely. So, on redoing the CSV from stratch it worked!