0

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

saba javad
  • 13
  • 2
  • Could you share `iris.csv` file? – Alperen Nov 03 '19 at 17:51
  • 1
    You need to make a [mre] including the input data. See also [ask] for more pointers. – wjandrea Nov 03 '19 at 17:56
  • okay, Sorry for the delay. I did solve it. ````reader = csv.reader(csvFile)```` had a prroblem in a few files. It sometimes read an empty array. putting an exception solved the problem for me. Thank you! – saba javad Nov 05 '19 at 10:25

0 Answers0