Reputation: 61
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np
import time
dt = 'i4,i4,i4,a5,f9'
month,day,year,time,price = np.loadtxt('spyTestTest.txt',
delimiter=' ',dtype = dt)
I am trying to run this code on some sample data (below)
8 18 2014 9:30 196.79
8 18 2014 9:31 196.8249
8 18 2014 9:32 196.825
8 18 2014 9:33 196.88
8 18 2014 9:34 196.887
8 18 2014 9:35 196.835
8 18 2014 9:36 196.81
8 18 2014 9:37 196.81
8 18 2014 9:38 196.81
However I am getting an error saying
Value Error: too many values to unpack.
I read online that this occurs when you have more variables than columns to parse, but it looks to me like I have 5 variables and 5 columns of text. Any advice?
Upvotes: 3
Views: 6697
Reputation: 41
as your input file already formatted use unpack=True, this should solve your problem
month,day,year,time_k,price = np.loadtxt('spyTestTest.txt', delimiter=' ',dtype = dt, unpack=True);
Upvotes: 4