Please please help!!
Having a lot of trouble with this code. The task here is to plot some information (High, Low and Medium) against dates associated with them.
The data is found in a .csv file, with the Headings as : Date, High, Medium, Low. The dates are in dd/mm/yyyy format.
So far, I've used genfromtxt to specify the columns and the datatype etc.. However, I think there's a problem with how Python is reading the columns - I keep getting either "Too many indices":
Traceback (most recent call last):
File "F:\Python\A1.py", line 14, in <module>
x = data[:,0]
IndexError: too many indices
OR if I use x = data[;,'Date] I get this:
Traceback (most recent call last):
File "F:\Python\A1.py", line 14, in <module>
x = data[:,'Date']
ValueError: invalid literal for long() with base 10: 'Date'
Here is the complete code:
import pylab as py
import numpy as np
import datetime as dt
import csv
data = np.genfromtxt('F:\\Python\\All.csv', usecols=(0,1,2,3), names=True, skip_header=0, dtype=[('Date', 'S10')]),('High','f8'),('Medium','f8'),('Low','f8')], delimiter = ',')
print data
x = data[:,Date]
y1 = data[:,1]
y2 = data[:,2]
y3 = data[:,3]
Date2 = []
for x in data:
date_format = dt.datetime.strptime((str(x)), '%d/%m/%Y')
Date2.append.date_format
Thanks!