I am new to coding and I can understand that this is a very basic question
I have a dataframe as:
df
Unnamed: 0 time home_team away_team full_time_result both_teams_to_score double_chance
-- ------------ ------------------- ------------- -------------- ---------------------------------- ------------------------- ------------------------------------
0 0 2021-01-12 18:00:00 Sheff Utd Newcastle {'1': 2400, 'X': 3200, '2': 3100} {'yes': 2000, 'no': 1750} {'1X': 1360, '12': 1360, '2X': 1530}
1 1 2021-01-12 20:15:00 Burnley Man Utd {'1': 7000, 'X': 4500, '2': 1440} {'yes': 1900, 'no': 1900} {'1X': 2620, '12': 1180, '2X': 1100}
2 2 2021-01-12 20:15:00 Wolverhampton Everton {'1': 2450, 'X': 3200, '2': 3000} {'yes': 1950, 'no': 1800} {'1X': 1360, '12': 1360, '2X': 1530}
3 3 2021-01-13 18:00:00 Man City Brighton {'1': 1180, 'X': 6500, '2': 14000} {'yes': 2040, 'no': 1700} {'1X': 1040, '12': 1110, '2X': 4500}
4 4 2021-01-13 20:15:00 Aston Villa Tottenham {'1': 2620, 'X': 3500, '2': 2500} {'yes': 1570, 'no': 2250} {'1X': 1500, '12': 1280, '2X': 1440}
5 5 2021-01-14 20:00:00 Arsenal Crystal Palace {'1': 1500, 'X': 4000, '2': 6500} {'yes': 1950, 'no': 1800} {'1X': 1110, '12': 1220, '2X': 2500}
6 6 2021-01-15 20:00:00 Fulham Chelsea {'1': 5750, 'X': 4330, '2': 1530} {'yes': 1800, 'no': 1950} {'1X': 2370, '12': 1200, '2X': 1140}
7 7 2021-01-16 12:30:00 Wolverhampton West Brom {'1': 1440, 'X': 4200, '2': 7500} {'yes': 2250, 'no': 1570} {'1X': 1100, '12': 1220, '2X': 2620}
8 8 2021-01-16 15:00:00 Leeds Brighton {'1': 2000, 'X': 3600, '2': 3600} {'yes': 1530, 'no': 2370} {'1X': 1280, '12': 1280, '2X': 1720}
I am looking to format the dictionary list nicely and get the dataframe as e.g. the full_time_result column would be split into full_time_result_1, full_time_result_X, full_time_result_2 and the same for both_teams_to_score and double_chance as below:
Unnamed: 0 time home_team away_team full_time_result_1 full_time_result_x full_time_result_2 both_teams_to_score_yes both_teams_to_score_no double_chance_1X
-- ------------ ------------------- ------------- -------------- ---------------------------------- ------------------------- ------------------------------------
I am following this example given here but I am unable to get it to work. Here is my code:
import pandas as pd
from tabulate import tabulate
df = pd.read_csv(r'C:\Users\Harshad\Desktop\re.csv')
df['full_time_result'] = df['full_time_result'].apply(pd.Series)
print(tabulate(df, headers='keys'))
Unnamed: 0 time home_team away_team full_time_result both_teams_to_score double_chance
-- ------------ ------------------- ------------- -------------- ---------------------------------- ------------------------- ------------------------------------
0 0 2021-01-12 18:00:00 Sheff Utd Newcastle {'1': 2400, 'X': 3200, '2': 3100} {'yes': 2000, 'no': 1750} {'1X': 1360, '12': 1360, '2X': 1530}
1 1 2021-01-12 20:15:00 Burnley Man Utd {'1': 7000, 'X': 4500, '2': 1440} {'yes': 1900, 'no': 1900} {'1X': 2620, '12': 1180, '2X': 1100}
2 2 2021-01-12 20:15:00 Wolverhampton Everton {'1': 2450, 'X': 3200, '2': 3000} {'yes': 1950, 'no': 1800} {'1X': 1360, '12': 1360, '2X': 1530}
3 3 2021-01-13 18:00:00 Man City Brighton {'1': 1180, 'X': 6500, '2': 14000} {'yes': 2040, 'no': 1700} {'1X': 1040, '12': 1110, '2X': 4500}
4 4 2021-01-13 20:15:00 Aston Villa Tottenham {'1': 2620, 'X': 3500, '2': 2500} {'yes': 1570, 'no': 2250} {'1X': 1500, '12': 1280, '2X': 1440}
Help would be greatly appreciated.