0

I have a csv file, and I try to open with

def datetime_from_str(string):
    return dt.datetime.strptime(string, '%Y-%m-%d %H:%M:%S')

def main():

    data = genfromtxt(
        csv_name, delimiter=';', skip_header=1, dtype=None,
        names=col_names, converters={'fecha':datetime_from_str}
    )

but, when I try to call one column

 print type(data), data[:,1]

I get this error

<type 'numpy.ndarray'>
Traceback (most recent call last):
...
IndexError: too many indices
JuanPablo
  • 23,792
  • 39
  • 118
  • 164
  • It sounds like your `data` array is one-dimensional, so when you try to access `data[:,1]` an error is thrown. Is the delimiter correct? If you print out `data`, does it look right? – jme Apr 02 '15 at 14:23
  • yes, the data look right `[ ('some value', datetime.datetime(2014, 4, 22, 15, 5, 3), 1061.932,` ... – JuanPablo Apr 02 '15 at 14:25
  • `data` is a 1d structured array - with 'fields' – hpaulj Apr 02 '15 at 14:25

1 Answers1

0

Looks like your data is a 1d structured array. Its dtype lists the fields, with name taken from your col_names. Show us data.dtype.

Assuming the 2nd name is fetcha ('date'), then you should be able access those dates with

data['fetcha']  # or
data[col_names[1]] 
hpaulj
  • 221,503
  • 14
  • 230
  • 353