-2
List = ['Stevie', '$101', '(33%)', 'Hezazeb', '$3.60', '(85%)', 
        'Boga Dreams', '$5.50', '(25%)', 'Grey Detective', '$8.00', '(22%)', 
        'Bring A Dame', '$26.00', '(8%)', 'Sandhill', '$5.00', '(100%)', 
        'Burgundy Rules', '$41.00', '(17%).', 'Luxitorah', '$7.50', '(0%)', 
        'Play On Words', '$21.00', '(14%).', 'Cranky Sheriff', '$13.00', '(8%)']

I want this list to store in a dataframe with 3 columns in the following manner. I am fetching this data from a website so i cant do this manually.

- Playername Bids probability   
- Stevie.    $101.   33% 
- Hezazeb.   $3.60.  85%
- .
- .
- .

and so on

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
zee
  • 31
  • 5

2 Answers2

0

This works even with the non-fixed data - you just need to preprocess:

# jumbled data needs preprocessing - if you have cleaner data skip that step
data = ['Stevie', '$101', '(33%)', 'Hezazeb', '$3.60', '(85%)', 'Boga', 
'Dreams', '$5.50', '(25%)', 'Grey', 'Detective', '$8.00', '(22%)', 'Bring', 
'A', 'Dame', '$26.00', '(8%)', 'Sandhill', '$5.00', '(100%)', 'Burgundy', 
'Rules', '$41.00', '(17%).', 'Luxitorah', '$7.50', '(0%)', 'Play', 'On', 
'Words', '$21.00', '(14%).', 'Cranky', 'Sheriff', '$13.00', '(8%)']

# Preprocess: 
# join all into one string
# fix irritating ). to be )
# fix $ to be |$ 
# fix ) to be )|  to enable splitting at | for well formed data
d = " ".join(data).replace(").", ")").replace(")", 
    ")|").replace("$", "|$").replace("(", "|(")

# remove pending last |
# split at | into well formatted list
d = d.rstrip("|").split("|")

import pandas as pd

# use list slicing to fill dataframe from source list
df = pd.DataFrame({"Name": d[0::3], "Bet": d[1::3], "probability": d[2::3]})

print(df)

Output:

               Name      Bet probability
0           Stevie     $101        (33%)
1          Hezazeb    $3.60        (85%)
2      Boga Dreams    $5.50        (25%)
3   Grey Detective    $8.00        (22%)
4     Bring A Dame   $26.00         (8%)
5         Sandhill    $5.00       (100%)
6   Burgundy Rules   $41.00        (17%)
7        Luxitorah    $7.50         (0%)
8    Play On Words   $21.00        (14%)
9   Cranky Sheriff   $13.00         (8%)

See Understanding slice notation if that is unclear to you.

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
-1

To convert a list into data frame you should either have tuples or pd.series or any dataframe object,in your case you should convert them into dict,i suggest manually,because the data is very diff for every point and then fill the missing columns by nan.