I am trying to clean a column:
df:
+-----+------------------+--------------------+--------------------+--------------+--------------+
| | league | home_team | away_team | home_score | away_score |
+=====+==================+====================+====================+==============+==============+
| 0 | Champions League | APOEL | Qarabag | 1 | 2 |
+-----+------------------+--------------------+--------------------+--------------+--------------+
| 1 | Champions League | FC Copenhagen | TNS | 1 | 0 |
+-----+------------------+--------------------+--------------------+--------------+--------------+
| 2 | Champions League | AIK | Maribor | 3 | 2 ET |
+-----+------------------+--------------------+--------------------+--------------+--------------+
expected
df:
+-----+------------------+--------------------+--------------------+--------------+--------------+
| | league | home_team | away_team | home_score | away_score |
+=====+==================+====================+====================+==============+==============+
| 0 | Champions League | APOEL | Qarabag | 1 | 2 |
+-----+------------------+--------------------+--------------------+--------------+--------------+
| 1 | Champions League | FC Copenhagen | TNS | 1 | 0 |
+-----+------------------+--------------------+--------------------+--------------+--------------+
| 2 | Champions League | AIK | Maribor | 3 | 2 |
+-----+------------------+--------------------+--------------------+--------------+--------------+
I am trying
df['away_score'] = df['away_score'].astype(str).str.replace('(\s?\w+)$', '', regex=True)
(works on regex101 but not in pandas)
But all the data in column is being replaced.
+-----+------------------+--------------------+--------------------+--------------+--------------+
| | league | home_team | away_team | home_score | away_score |
+=====+==================+====================+====================+==============+==============+
| 0 | Champions League | APOEL | Qarabag | 1 | |
+-----+------------------+--------------------+--------------------+--------------+--------------+
| 1 | Champions League | FC Copenhagen | TNS | 1 | |
+-----+------------------+--------------------+--------------------+--------------+--------------+
| 2 | Champions League | AIK | Maribor | 3 | 2 |
+-----+------------------+--------------------+--------------------+--------------+--------------+
What should be the correct regex?