I am new to using Numpy. I am trying to simplify reading in features and setting initializing my numpy arrays.
I want the feature_name to contain all features for columns 0-4, _X to contain all rows and columns 0 - 4 and _y to contain all rows for column 5.
My code works, but its not as succinct or understandable as I would like it to be
import csv
import numpy as np
# read in the data as rows
with open('data.csv', 'rb') as csvfile:
_reader = csv.reader( csvfile, delimiter =',',quotechar ='"')
# Read in the feature names into an array
feature_names = _reader.next()
# Read the in the sample data
_X, _y = [], []
for row in _reader:
_X.append( row ) #read in plant
_y.append( row[ 5])
feature_names = np.array(feature_names)
_X = np.array( _X)
_y = np.array( _y)
_X = _X[:, [0,1,2,3,4]]
_names = feature_names[[ 0,1,2,3,4]]
I really appreciate your assistance and want to improve my coding! Thanks in advance