[Numpy-discussion] Extracting data from genfromtxt?
rohaq at dearinternet.com
Fri Mar 18 16:27:17 EDT 2011
I've got a CSV file with the following layout:
...etc., and I've loaded it using the following:
import numpy as np
data = np.genfromtxt('file.csv',delimiter=',',dtype=None,names=True)
Resulting in the following:
array([(1, 0, 0), (2, 0, 0), (3, 0, 0), ..., (16382, 0, 0), (16383, 0, 0),
(16384, 0, 0)],
dtype=[('Location', '<i8'), ('Result1', '<i8'), ('Result2', '<i8')])
I want to plot the data in matplotlib.pyplot, but I'm having trouble
reshaping the data into something it'll recognise. I can pull the
Location easily enough with data['Location'], but I need to get the
results from every other column present.
There could be a lot more than 2 other columns, Result3,Result4, etc.,
so I need to code it to be scalable; if this were acting like a normal
dict, I could write a loop that iterates over the keys, and loads the
results data into a new object, but I can't seem to find a function
that will return the keys so that I can do this.
Can anybody offer any tips for this? I'm fairly new to Python/Numpy,
so any help is appreciated.
More information about the NumPy-Discussion