Have you ever wondered how powerful Pandas are?

self.filepath = filepath

with open(filepath,”r”) as csv_file:
reader = csv.reader(csv_file, delimiter = ‘,’)
#remove white spaces spaces in data
data = [[x.strip() for x in row] for row in reader]

#convert data to a numpy array
self.data = np.array(data)

#pick out numeric data only
arr_indx = np.where(self.data[1,:] == ‘numeric’)

#change arr_indx from 2D to 1D
arr_indx = np.array(arr_indx).flatten()

#ensure we have only numeric headers
self.headers = self.data[0,arr_indx].tolist()

#create empy list for header indexes
header_indx = []

#append length of arr_inx to header_indx
for i in range(len(arr_indx)):

#zip header_indx with self.headers to form dictionary of header2col
d1 = zip(self.headers,header_indx)
self.header2col = dict(d1)

#have self.data display only the data without headers and datatypes
self.data = self.data[2:,arr_indx]

#convert self.data to type float
self.data = self.data.astype(‘float64’)

#load iris csv as pandas dataframe
data = pd.read_csv(‘filepath’)

#print column names

#Slicing-1st five data samples


def select_data(self, headers, [])

col_indices = []

for i in headers:

if rows == []:
return self.data[:,col_indices]
return self.data[np.ix_(rows,col_indices)]

#select subset of data
data_1 = data[[‘variable name’]]




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store