Python Forum
Convert Excel to complex list - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Convert Excel to complex list (/thread-27825.html)



Convert Excel to complex list - and2handles - Jun-23-2020

Hey guys,

I am still a bloody beginner and struggeling with the conversion of excel data into a python list.
My code for getting the data is this:

import pandas as pd

df = pd.read_excel('C:/Users/and2handles/Desktop/Temp/Python/testlist.xlsx', sheet_name="Tabelle1") 
print(df)


The excel sheet has data from A:1 to D:4. My result for that data is:

Values Names x-axis y-axis
0 ..... 1 ..... a ..... 40.....31
1 ..... 2 ..... b ..... 50 .....32
2 ..... 3 ..... c ..... 60 ..... 33
3 ..... 4 ..... d ..... 70 ..... 34

What do I have to do that my data looks like this?

df = [[1,a,40,31],[2,b,50,21],...]


RE: Convert Excel to complex list - DPaul - Jun-23-2020

If you have column names, you may try this:
df = panda.DataFrame(sheet)
record = []
record2D = []
for i in df.index:
    record.append(df['colname1'][i])
    record.append(df['colname2'][i])
    ...

    record2D.append(record)
    record =[]
Paul