Pandas GroupBy.nth功能与NaN异常行为

时间:2017-10-01 14:32:53

标签: python python-3.x pandas pandas-groupby

让pandas dataframe:

df = pd.DataFrame({'A': [np.nan, 2, 3],
                   'B': ["hello", "mr", "python"]})

我将按“A”列分组,其中缺少“A”的第一个值:

g = df.groupby("A")

使用g.nth(0)我得到了这个奇怪的结果:

      B
A          
2.0      mr
3.0   hello
3.0  python   
对于值A = 3.0,

“hello”不应出现。

但是将参数dropna = "any"传递给nth会得到适当的结果,即:

          B
A          
2.0      mr
3.0  python

我有大熊猫0.19.2。

有人可以解释一下这种异常的原因吗?

0 个答案:

没有答案