Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weight Distribution
#2
There is a problem with your data, not all lines have the same number of items.

Lines C and D have 8 items, but you only have 7 column names, so where will you put item 8? E has 6 items and F has 5 items. Bit of a problem.

You should make sure your data is correct before you start. I changed the data a bit.

This will give you a database, then perhaps you can explain what it is that you want to do more clearly?

import pandas as pd

# this will cause problems because you only have 7 column names
# but C and D have 8 items E has 6 items and F has 5 items
datastring = """A A1 Banking Financial 4.486 3.522 4.419
B BBB3 Banking Financial 0.445 0.559 0.701
C A1 Financial Services Financial 0.821 0.994 1.274
D A3 Financial Services Financial 2.744 3.445 4.415
E A2 Financial Services Financial 1.919
F A1 Insurance Financial 0.393"""

# revised data
datastring = '''A A1 Banking Financial 4.486 3.522 4.419
B BBB3 Banking Financial 0.445 0.559 0.701
C A1 Financial Services 0.821 0.994 1.274
D A3 Financial Services 2.744 3.445 4.415
E A2 Financial Services 1.919 5.791 2.348
F A1 Insurance Financial 0.393 0.998 3.726'''

cols = ['Security', 'CompRating', 'Level_3', 'Level_2', 'parent_weight', 'child_weight', 'Total'] # 7 column names

lists = [s.split() for s in datastring.split('\n')]
df = pd.DataFrame(lists, columns=cols)
You could make an empty dataframe and then read the lists in 1 by 1, but you still need another column name!
Reply


Messages In This Thread
Weight Distribution - by 11drk9 - Mar-10-2024, 02:31 AM
RE: Weight Distribution - by Pedroski55 - Mar-10-2024, 09:12 AM
RE: Weight Distribution - by 11drk9 - Mar-10-2024, 11:44 PM
RE: Weight Distribution - by 11drk9 - Mar-11-2024, 12:00 AM
RE: Weight Distribution - by Pedroski55 - Mar-11-2024, 09:08 AM
RE: Weight Distribution - by 11drk9 - Mar-11-2024, 01:48 PM
RE: Weight Distribution - by 11drk9 - Mar-11-2024, 05:48 PM
RE: Weight Distribution - by Pedroski55 - Mar-11-2024, 06:01 PM
RE: Weight Distribution - by 11drk9 - Mar-11-2024, 06:38 PM
RE: Weight Distribution - by Pedroski55 - Mar-12-2024, 12:41 PM
RE: Weight Distribution - by 11drk9 - Mar-12-2024, 07:00 PM
RE: Weight Distribution - by Pedroski55 - Mar-13-2024, 06:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  distribution fit Glaucio 1 347 Apr-07-2024, 12:30 AM
Last Post: Larz60+
Information Best distribution method inovermyhead100 0 625 Jul-19-2023, 07:39 AM
Last Post: inovermyhead100
  How do I use a whl puython distribution? barryjo 6 1,931 Aug-15-2022, 03:00 AM
Last Post: barryjo
  Help with basic weight converter PythonSquizzel 3 1,529 Jun-29-2022, 02:42 PM
Last Post: deanhystad
  Python Networkx: Visualize an edge weight with a bubble/circle uvw 0 2,067 Sep-01-2021, 06:26 AM
Last Post: uvw
  Coin Toss - Distribution lasek723 6 3,269 Oct-04-2020, 01:36 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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