I'm using
data1 = list(map(list, zip(*data2)))
to convert a lists of list to transpose the list. But it ends up giving me an empty array.
The strange part in of this scenario is the fact that this code work for some files. please suggest the course of action. data2
is being populated, but for some reason data1 becomes empty after executing data1 = list(map(list, zip(*data2)))
def file_read():
data = list()
mapped_number = list()
to_be_rows = list()
#change file name
with open('iris.csv', 'r') as csvFile:
reader = csv.reader(csvFile)
data2 = list(reader)
rows = len(data2)
cols = len(data2[0])
csvFile.close()
#data1 = data2.copy()
#data1 = np.asarray(data2)
#data1 = np.transpose(data1)
data1 = list(map(list, zip(*data2)))
#data1=np.transpose(data2)
#print(data1)
for lists in data1:
mapped_number.append(your_function(lists,count))
#print(lists)
for i in range(0,rows):
to_be_rows.clear()
for number in mapped_number:
to_be_rows.append(number[i])
final_list.append(to_be_rows[:])
I expect the data2
to be the transpose version of data1