I have the following dataframe in Python that lists team lineage for a Formula 1 team in that it identifies when teams change name and what they change to:
import pandas as pd
teams = pd.DataFrame({'type': {0: 'new', 1: 'change', 2: 'change', 3: 'change'},
'orig_event_id': {0: nan, 1: '2009-01-Q', 2: '2012-01-Q', 3: '2017-01-Q'},
'orig_team_id': {0: nan,
1: 'Tyrrell_Racing_Organisation',
2: 'Mercedes_AMG_Petronas_F1_Team',
3: 'Mercedes_AMG_Petronas_Motorsport'},
'event_id': {0: '1970-01-Q', 1: '2010-01-Q', 2: '2017-01-Q', 3: '2020-01-Q'},
'new_team_id': {0: 'Tyrrell_Racing_Organisation',
1: 'Mercedes_AMG_Petronas_F1_Team',
2: 'Mercedes_AMG_Petronas_Motorsport',
3: 'Mercedes_AMG_Petronas_F1_Team'}})
The 'orig_event_id' is the event in which the team name changes and the 'event_id' is how long the name lasts to, if that helps.
I also have this dataframe of drivers and races that I would like to change the data of:
driver = pd.DataFrame({'index': {0: 22258, 1: 22279, 2: 22300, 3: 22317, 4: 22337},
'driver_id': {0: 'Lewis_Hamilton',
1: 'Lewis_Hamilton',
2: 'Lewis_Hamilton',
3: 'Lewis_Hamilton',
4: 'Lewis_Hamilton'},
'team_id': {0: 'Mercedes_AMG_Petronas_Motorsport',
1: 'Mercedes_AMG_Petronas_Motorsport',
2: 'Mercedes_AMG_Petronas_Motorsport',
3: 'Mercedes_AMG_Petronas_Motorsport',
4: 'Mercedes_AMG_Petronas_Motorsport'},
'event_id': {0: '2018-01-R',
1: '2018-02-R',
2: '2018-03-R',
3: '2018-04-R',
4: '2018-05-R'},
'season': {0: 2018, 1: 2018, 2: 2018, 3: 2018, 4: 2018},
'stage': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5}})
So essentially what I want is the team_id in the driver df to change from 'Mercedes_AMG_Petronas_Motorsport' to 'Mercedes_AMG_Petronas_F1_Team' and all of the team_id with 'Tyrrell_Racing_Organisation' to also change to 'Mercedes_AMG_Petronas_F1_Team' so that they're consistent from year-to-year.
Is there an easy way to do this? Let me know and appreciate any help!