I use Pandas and Numpy in Python3 with the following versions:
- Python 3.5.1 (via Anaconda 2.5.0) 64 bit
- Pandas 0.19.1
- Numpy 1.11.2 (perhaps not relevant here)
Here is the minimal code creating the problem:
import pandas as pd
import numpy as np
a = pd.DataFrame({'i' : [1,1,1,1,1], 'a': [1,2,5,6,100], 'b': [2, 4,10, np.nan, np.nan]})
a.set_index(keys='a', inplace=True)
v = a.groupby(level=0).apply(lambda x: x.sort_values(by='i')['b'].rolling(2, min_periods=0).mean())
v.index.names
This code is a simple group approach, but I do not understand the result:
FrozenList(['a', 'a'])
For some reason, the index of the result is ['a', 'a'], which seems like a pretty dubious choice from pandas. I would expect a simple ['a'].
Does anyone have an idea why Pandas prefers to duplicate a column in an index?
Thanks in advance.
source
share