lundi 4 juillet 2016

python matrix string transpose without using numpy or zip/ map


My current output is 3x1 matrix but I wish to have an output in horizontal matrix 1x3: ['apple', 'orange', 'grape']

My python version is 3.5.1 and I fail to install numpy, I get an error if using zip or map to transpose as my variable is string not an integer.

Here is my code

import csv
#import numpy as np

f1 = open('out.csv')
data = csv.reader(f1, delimiter=':')
print (data)
for row in data:
    #print(row)
    modules = print(row[2:])
    #for row in module:

    result = [[0,0]]

# iterate through rows
for i in modules:
    # iterate through columns
    for j in modules[0]:
        result[j][i] = X[i][j]

for r in result:
    print(r)  

#Try with zip/map
#print(map(data,zip(*module))
#with open('test.csv', 'wb') as f:
    #writer = csv.writer(f)
    #for row in module:
    #writer.writerow(module)
f1.close()

Error:

Traceback (most recent call last): File "python_exe2.py", line 15, in for i in modules: TypeError: 'NoneType' object is not iterable


Aucun commentaire:

Enregistrer un commentaire