'python dataframe count and replace value

I have a dataframe that contains an ID of carreer and a list of competitors, the list of competitors is variable, so the competitor that get last, is with the letter 'L' i'm using the function size with groupby, but i cannot get to replace to that letter, cause it returns a series data type.

df['competitor_place'] = df['competitor_place'].str.replace('L',str(df.groupby('id_career')['id_career'].size()))

How can i get to replace the L with the count of competitors in the career?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source