2

I have a dateframe named Mj_rank, with date as Datetime and index which looks like this:

                A      B     C ...
date
2016-01-29     False  False  True
2016-01-30     False  False  True
2016-02-01     True   True   True
  ....
2017-12-29     False  True   True

Currently, the data is daily, but I would like to resample the data into a new df that contains every 6 months nth.

Therefore I did:

Mj_rank_s = Mj_rank.resample('6M').asfreq().tail()

which gives me this output:

ValueError: cannot reindex from a duplicate axis

strangely enough, if I use other methods like max() or min() it works fine, but not "asfreq()".

I tried different ways based on existing stackoverflow suggestions like adding in front, but didn't work :

Mj_rank = Mj_rank.reset_index()
Mj_rank['date'] = pd.to_datetime(Mj_rank['date'])
Mj_rank = Mj_rank.set_index('date')

Thanks a lot!

Edit: Thanks to @jezrael he pointed out I had problems with duplicates using Mj_rank[Mj_rank.index.duplicated(keep=False)]

9
  • It looks like bug/ not implemented for duplicated dates + resample + asfreq :( Commented Jan 17, 2018 at 10:21
  • So is possible remove dupes dates? Commented Jan 17, 2018 at 10:22
  • I'm pretty confident there are no duplicated dates, which makes it even more strange. Commented Jan 17, 2018 at 10:29
  • 2
    So Mj_rank.index.is_unique return True ? Commented Jan 17, 2018 at 10:30
  • 2
    And Mj_rank[Mj_rank.index.duplicated(keep=False)] mo rows? Commented Jan 17, 2018 at 10:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.