Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

reset_index does not allow to specify level #2647

Closed
michaelaye opened this Issue Jan 6, 2013 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

michaelaye commented Jan 6, 2013

df has a 3-level multi-index, the 3rd level (level=2) is a time-index.

newseries has the time-index only:

newseries.head()
time 
2009-07-20 00:00:00.045000    312.591132
2009-07-20 00:00:00.173000    312.589225
2009-07-20 00:00:00.301000    312.587320
2009-07-20 00:00:00.429000    312.585419
2009-07-20 00:00:00.557000    312.583521

I now want to broadcast the newseries to the index of df, which looks like this:

df.index[0]

(1.0, 1.0, <Timestamp: 2009-07-20 00:00:00.045000>)

using reset_index with the level parameter:

df['bb2temp_interp'] = newseries.reset_index(df.index, level=2)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-cb55de3c4846> in <module>()
----> 1 df['bb2temp_interp'] = newseries.reset_index(df.index,level=0)

TypeError: reset_index() got multiple values for keyword argument 'level'

It looks like the level is pre-occupied with a default level setting from the method call?

According to this Stackoverflow issue answer from Chang She, this should work?
http://stackoverflow.com/questions/12461470/how-to-broadcast-on-a-single-index-in-hierarchically-indexed-dataframe

gerigk commented Jan 6, 2013

newseries.reset_index(df.index, level=2)

looks weird to me
did you mean

newseries.reset_index(level=2)

the first argument of reset_index is self and therefore newseries in this
case. df.index is interpreted as "level" (first positional argument) and then you provide "level=2" which makes it two values for the same argument (this explains the typerror).

Contributor

michaelaye commented Jan 6, 2013

oh darn, sorry. was a long pandas day for me yesterday. I really should wait a day or so before submitting something as an issue. Issue is, one day later I could already be so much further with a work-around and my project, I might forget about a problem I had before.

What I meant to be using is reindex and not reset_index.

@michaelaye michaelaye closed this Jan 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment