Nevermind. I figured it out. There are too many rows to unpack. when I separated the csv file into 2 files with ~30k rows each, it worked
python valueerror: too many values to unpack using numpy
-
13-10-2022 - |
Question
I am trying to extract information from a excel file into python, but I get this error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
main()
File "C:\Users\viral\Desktop\python\test.py", line 5, in main
date, time, temp = np.loadtxt('temperatures.csv', delimiter = ',', unpack = True, dtype = 'str')
ValueError: too many values to unpack
code:
import numpy as np
def main():
date, time, temp = np.loadtxt('temperature.csv', delimiter = ',', unpack = True, dtype = 'str')
import itertools
groups = itertools.groupby(zip(date, temp), lambda dv:dv[0])
list_of_lists = [[d] + [v[1] for v in values] for d, values in groups]
list_of_lists = list_of_lists[:len(list_of_lists)-1]
x = 0
while (x < len(list_of_lists)):
list_of_lists[x] = [float(i) for i in list_of_lists[x]]
print list_of_lists[x]
x += 1
print len(list_of_lists)
excel file looks like this. it is in csv format:
please help debug
raw data from csv file:
20130102 9:30:00 AM 34.75
20130102 9:31:00 AM 34.66
20130102 9:32:00 AM 34.6
20130102 9:33:00 AM 34.6
20130102 9:34:00 AM 34.61
20130102 9:35:00 AM 34.65
20130102 9:36:00 AM 34.65
it goes on for 65,208 rows
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow