Let df be a data frame.
In [1]: import pandas as pd
...: df = pd.DataFrame(columns = ['Home', 'Score', 'Away'])
...: df.loc[0] = ['Team A', '3-1', 'Team B']
...: df.loc[1] = ['Team B', '2-1', 'Team A']
...: df.loc[2] = ['Team B', '2-2', 'Team A']
...: df.loc[3] = ['Team A', '0-1', 'Team B']
In [2]: df
Out[2]:
Home Score Away
0 Team A 3-1 Team B
1 Team B 2-1 Team A
2 Team B 2-2 Team A
3 Team A 0-1 Team B
I want to make df_1 out of df.
In [4]: df_1
Out[4]:
Team A Team B
0 3 1
1 1 2
2 2 2
3 0 1
What is the easiest way?
As a beginner, I can split the 'Score' column into two columns and then loop over the other columns and get df_1, but I guess there should be an easier way of doing that, probably with a lambda function or group_by method.
Any ideas?