In [1]:
myrowdata = [['cell#','mv','peak'],
['fk1',1,2],
['fk2',2,25],
['fk3',43,-45]]
In [ ]:
In [2]:
mycoldata={}
all_col_header = myrowdata[0]
all_col_header
Out[2]:
In [3]:
col_hdr = all_col_header[0]
col_hdr
Out[3]:
In [4]:
mycoldata[col_hdr] = []
mycoldata
Out[4]:
In [5]:
value_list = myrowdata[1]
mycoldata[col_hdr].append(value_list[0])
mycoldata
Out[5]:
In [6]:
value_list = myrowdata[2]
mycoldata[col_hdr].append(value_list[0])
mycoldata
Out[6]:
In [7]:
value_list = myrowdata[3]
mycoldata[col_hdr].append(value_list[0])
mycoldata
Out[7]:
In [ ]:
In [ ]:
In [ ]:
In [8]:
col_hdr = all_col_header[1]
col_hdr
Out[8]:
In [9]:
mycoldata[col_hdr] = []
mycoldata
Out[9]:
In [10]:
value_list = myrowdata[1]
mycoldata[col_hdr].append(value_list[1])
mycoldata
Out[10]:
In [11]:
value_list = myrowdata[2]
mycoldata[col_hdr].append(value_list[1])
mycoldata
Out[11]:
In [12]:
value_list = myrowdata[3]
mycoldata[col_hdr].append(value_list[1])
mycoldata
Out[12]:
In [ ]:
In [ ]:
In [ ]:
In [13]:
col_hdr = all_col_header[2]
col_hdr
Out[13]:
In [14]:
mycoldata[col_hdr] = []
mycoldata
Out[14]:
In [15]:
value_list = myrowdata[1]
mycoldata[col_hdr].append(value_list[2])
mycoldata
Out[15]:
In [16]:
value_list = myrowdata[2]
mycoldata[col_hdr].append(value_list[2])
mycoldata
Out[16]:
In [17]:
value_list = myrowdata[3]
mycoldata[col_hdr].append(value_list[2])
mycoldata
Out[17]:
Now we are adding a loop to append the row values to each key of dictionary
In [18]:
mycoldata = {}
In [19]:
col_hdr = all_col_header[2] #peak
mycoldata[col_hdr] = []
for row_index in range(1,4):
value_list = myrowdata[row_index]
mycoldata[col_hdr].append(value_list[2])
mycoldata
Out[19]:
In [20]:
col_hdr = all_col_header[1] #mv
mycoldata[col_hdr] = []
for row_index in range(1,4):
value_list = myrowdata[row_index]
mycoldata[col_hdr].append(value_list[1])
mycoldata
Out[20]:
In [22]:
col_hdr = all_col_header[0] # Cell#
mycoldata[col_hdr] = []
for row_index in range(1,4):
value_list = myrowdata[row_index]
mycoldata[col_hdr].append(value_list[0])
mycoldata
Out[22]:
In [21]:
for i in range(1,4):
print(i)
In [34]:
myrowdata = [['cell#','mv','peak','col4'],
['fk1',1,2,8],
['fk2',2,25,7],
['fk3',43,-45,8],
['fk4',33,-4,8]]
def transform_row_to_col(myrowdata):
all_col_header = myrowdata[0] # first row has to be col header (this is a must requirment)
mycoldata = {}
for col_index in range(0, len(all_col_header)):
col_hdr = all_col_header[col_index]
mycoldata[col_hdr] = []
for row_index in range(1, len(myrowdata)):
value_list = myrowdata[row_index]
mycoldata[col_hdr].append(value_list[col_index])
return mycoldata
Out[34]:
In [29]:
len(myrowdata)
Out[29]:
In [32]:
len(all_col_header)
Out[32]:
In [ ]:
In [1]:
from sklearn.datasets import load_iris
from sklearn import tree
import numpy as np
from sklearn.externals.six import StringIO
#import pydot
iris = load_iris();
iris
Out[1]:
In [ ]:
In [ ]: