I am using the numpy library in Python to import CSV
file data into a ndarray
as follows:
data = np.genfromtxt('mydata.csv',
delimiter='\,', dtype=None, names=True)
The result provides the following column names:
print(data.dtype.names)
('row_label',
'MyDataColumn1_0',
'MyDataColumn1_1')
The original column names are:
row_label, My-Data-Column-1.0, My-Data-Column-1.1
It appears that NumPy
is forcing my column names to adopt C-style variable name formatting. Yet there are many cases where my Python scripts require access to columns according to column name, so I need to ensure that column names remain constant. To accomplish this either NumPy
needs to preserve the original column names or else I need to convert my column names to the format NumPy
is using.
Is there a way to preserve the original column names during import?
If not, is there an easy way to convert column labels to use the format
NumPy
is using, preferably using someNumPy
function?