Python Forum
Convert Excel to complex list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert Excel to complex list
#1
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],...]
Reply
#2
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Excel File with a list of values huzzug 4 1,217 Nov-03-2023, 05:35 PM
Last Post: huzzug
  trouble reading string/module from excel as a list popular_dog 0 417 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  convert string to float in list jacklee26 6 1,898 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  convert a list to links Pir8Radio 3 1,096 Nov-28-2022, 01:52 PM
Last Post: Pir8Radio
  convert this List Comprehensions to loop jacklee26 8 1,504 Oct-21-2022, 04:25 PM
Last Post: deanhystad
  Convert Excel file into csv with Pipe symbol.. mg24 4 1,324 Oct-18-2022, 02:59 PM
Last Post: Larz60+
  list from excel devilonline 4 1,367 Jun-22-2022, 11:00 PM
Last Post: devilonline
  Convert list to interger Clives 5 1,624 May-09-2022, 12:53 PM
Last Post: deanhystad
  Compare two Excel sheets with Python and list diffenrences dmkfon 1 14,613 Oct-09-2021, 03:30 PM
Last Post: Larz60+
  How do I read in a Formula in Excel and convert it to do the computation in Python? JaneTan 2 2,638 Jul-07-2021, 02:06 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020