Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas confused
#5
Yes if the goal to take data out Pandas to a list then it will work,as column index don't get used.
If take that list back into DataFrame then it will automatically give column index.
>>> data = Qdf.values.tolist()
>>> data
[['AF-10', 744.42],
 ['AF-10', 1243.68],
 ['AF-20', 90.0],
 ['BA-40', -1425.0],
 ['BA-40', 1425.0],
 ['BA-40', 1425.0],
 ['BA-40', 1425.0],
 ['BA-50', 150.0],
 ['BO-30', 16514.61],
 ['BR-10', 528.35]]
>>> type(data) # A normal Python list
<class 'list'>
>>> 
>>> import pandas as pd
>>> 
>>> df = panda.DataFrame(data)
>>> df
       0         1
0  AF-10    744.42
1  AF-10   1243.68
2  AF-20     90.00
3  BA-40  -1425.00
4  BA-40   1425.00
5  BA-40   1425.00
6  BA-40   1425.00
7  BA-50    150.00
8  BO-30  16514.61
9  BR-10    528.35
>>> df = df.rename(columns={0: 'Name', 1: 'Cost'})
>>> df
    Name      Cost
0  AF-10    744.42
1  AF-10   1243.68
2  AF-20     90.00
3  BA-40  -1425.00
4  BA-40   1425.00
5  BA-40   1425.00
6  BA-40   1425.00
7  BA-50    150.00
8  BO-30  16514.61
9  BR-10    528.35
>>> type(df) # A DataFrame
<class 'pandas.core.frame.DataFrame'>
Reply


Messages In This Thread
Pandas confused - by DPaul - Sep-18-2021, 07:26 AM
RE: Pandas confused - by snippsat - Sep-18-2021, 07:42 AM
RE: Pandas confused - by DPaul - Sep-18-2021, 08:12 AM
RE: Pandas confused - by DPaul - Sep-18-2021, 09:38 AM
RE: Pandas confused - by snippsat - Sep-18-2021, 10:46 AM
RE: Pandas confused - by jefsummers - Sep-18-2021, 03:32 PM
RE: Pandas confused - by DPaul - Sep-19-2021, 06:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  String int confused janeik 7 1,087 Aug-02-2023, 01:26 AM
Last Post: deanhystad
  I am confused with the key and value thing james1019 3 978 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  is and '==' i'm confused hshivaraj 6 2,733 Sep-15-2021, 09:45 AM
Last Post: snippsat
  Confused with 'flags' tester_V 10 4,943 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Simple Tic Tac Toe but I'm confused Izith 1 2,205 Sep-26-2020, 04:42 PM
Last Post: Larz60+
  I am really confused with this error. Runar 3 3,040 Sep-14-2020, 09:27 AM
Last Post: buran
  Confused on how to go about writing this or doing this... pythonforumuser 3 2,503 Feb-10-2020, 09:15 AM
Last Post: snippsat
  Dazed and confused... RodNintendeaux 10 7,535 May-28-2017, 01:32 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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