I have a dataset for esports matches and I want to associate competition with each match row
JavaScript
x
7
1
Time team1 team2 score1 score2
2
0 Competition1 nan nan nan nan
3
1 2/15/2021 4:30 AM Reckoning Headshot 1 0
4
2 Competition2 nan nan nan nan
5
3 2/15/2021 9:00 AM Movistar Riders 1 0
6
4 2/15/2021 10:00 AM eMonkeyz G2 Arctic 0 1
7
I want it like that:
JavaScript
1
5
1
Competition Time team1 team2 score1 score2
2
0 Competition1 2/15/2021 4:30 AM Reckoning Headshot 1 0
3
1 Competition2 2/15/2021 9:00 AM Movistar Riders 1 0
4
2 Competition2 2/15/2021 10:00 AM eMonkeyz G2 Arctic 0 1
5
Advertisement
Answer
Let us try where
with ffill
after select the string with startswith
JavaScript
1
9
1
df['Competition'] = df.Time.where(df.Time.str.startswith('Competition')).ffill()
2
df.dropna(inplace=True)
3
df
4
Out[118]:
5
Time team1 team2 score1 score2 Competition
6
1 2/15/20214:30AM Reckoning Headshot 1.0 0.0 Competition1
7
3 2/15/20219:00AM Movistar Riders 1.0 0.0 Competition2
8
4 2/15/202110:00AM eMonkeyz G2Arctic 0.0 1.0 Competition2
9