I want to split a string that I have in a specific column of a DataFrame, get the numbers from the two new series, and assign the values to four new columns.
Before any modification the "Score" column on Saison looks like this:
0    \n3:2 (1:1) \n
1    \n0:2 (0:2) \n
2    \n1:1 (1:0) \n
3    \n1:1 (1:1) \n
4    \n2:0 (2:0) \n
The output that I want is this:
  Tore_Heim Tore_Auswärts Tore_Heim_HZ Tore_Auswärts_HZ
0         3             2            1                1
1         0             2            0                2
2         1             1            1                0
3         1             1            1                1
4         2             0            2                0
I have found a solution using list comprehension like this:
scores["Tore_Heim"] = pd.DataFrame([re.findall("\d+", scores[0][i]) for i in range(len(scores))]).loc[:, 0]
scores["Tore_Auswärts"] = pd.DataFrame([re.findall("\d+", scores[0][i]) for i in range(len(scores))]).loc[:, 1]
scores["Tore_Heim_HZ"] = pd.DataFrame([re.findall("\d+", scores[1][i]) for i in range(len(scores))]).loc[:, 0]
scores["Tore_Auswärts_HZ"] = pd.DataFrame([re.findall("\d+", scores[1][i]) for i in range(len(scores))]).loc[:, 1]
A second question is whether line 2 and 3 could be combined into one.