Is there a built in Python/pandas function to rename duplicate columns in a pandas.DataFrame?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Ancient Construction
--
Chapters
00:00 Question
00:51 Accepted answer (Score 6)
01:13 Thank you
--
Full question
https://stackoverflow.com/questions/6361...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Ancient Construction
--
Chapters
00:00 Question
00:51 Accepted answer (Score 6)
01:13 Thank you
--
Full question
https://stackoverflow.com/questions/6361...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas
#avk47
ACCEPTED ANSWER
Score 7
but I could not find a handy way to do this to a DataFrame object already
To an existing dataframe we have to resort to some code, there is no builtin;
s = pd.Series(df.columns)
df.columns= df.columns+s.groupby(s).cumcount().replace(0,'').astype(str)
x x1 y
0 2 5 1
1 1 9 3
2 4 1 2