Reshape of pandas series?

前端 未结 5 1200
轮回少年
轮回少年 2020-12-17 10:32

It looks to me like a bug in pandas.Series.

a = pd.Series([1,2,3,4])
b = a.reshape(2,2)
b

b has type Series but can not be displayed, the l

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 11:11

    You can call reshape on the values array of the Series:

    In [4]: a.values.reshape(2,2)
    Out[4]: 
    array([[1, 2],
           [3, 4]], dtype=int64)
    

    I actually think it won't always make sense to apply reshape to a Series (do you ignore the index?), and that you're correct in thinking it's just numpy's reshape:

    a.reshape?
    Docstring: See numpy.ndarray.reshape

    that said, I agree the fact that it let's you try to do this looks like a bug.

提交回复
热议问题