ValueError: Could Not Convert String To Float: (pd.Series)
I'm failing to execute 'lambda function' on the following code snippet below. My desired goal is to split columns( btts_x & btts_y ) respectively for further maths calculatio
Solution 1:
Lets Try to split by raw string '\n\n', expand and rename the columns
df['x']=df.btts_x+ " "+df.btts_y
df1=df.join(df['x'].str.split(r'\n\n|\n|\s|\n', expand=True)).rename(columns={0:'btts_x_1',1:'btts_x_2',2:'btts_y_1',3:'btts_y_2'}).drop(columns=['x'])
print(df1)
Teams_x btts_x \
0 Leicester City vs Manchester United 1.55\n\n2.40
1 Aston Villa vs Crystal Palace 1.68\n\n2.14
2 Fulham vs Southampton 1.72\n\n2.08
3 Arsenal vs Chelsea 1.79\n\n1.98
Teams_y btts_y btts_x_1 btts_x_2 btts_y_1 \
0 Leicester City vs Manchester United 1.50\n2.40 1.55 2.40 1.50
1 Aston Villa vs Crystal Palace 1.60\n2.20 1.68 2.14 1.60
2 Fulham FC vs Southampton FC 1.70\n2.00 1.72 2.08 1.70
3 Arsenal FC vs Chelsea FC 1.70\n2.00 1.79 1.98 1.70
btts_y_2
0 2.40
1 2.20
2 2.00
3 2.00
Post a Comment for "ValueError: Could Not Convert String To Float: (pd.Series)"