AndrewRoj
AndrewRoj

Reputation: 97

Renaming a duplicated value in a column

I am trying to remove a duplicate column value in a pandas dataframe. So for example:

2019-03-31
2019-06-30
2019-09-30
2019-12-31 
2020-03-31
2020-03-31

notice 2020-03-31 is duplicated. I would like to find the duplicated date and rename it as last quarter

conversely, If the column has no duplicates I want to leave as is. Can someone guide me in the right direction to do so?

Upvotes: 1

Views: 80

Answers (1)

Marco Cerliani
Marco Cerliani

Reputation: 22031

without loops

series = pd.Series(['2019-03-31',
           '2019-06-30',
           '2019-09-30',
           '2019-12-31', 
           '2020-03-31',
           '2020-03-31'])

series.loc[series.duplicated()] = 'last quarter'

Upvotes: 2

Related Questions