How to get the first column of a pandas DataFrame as a Series?

前端 未结 6 1517
花落未央
花落未央 2020-12-12 11:36

I tried:

x=pandas.DataFrame(...)
s = x.take([0], axis=1)

And s gets a DataFrame, not a Series.

6条回答
  •  醉话见心
    2020-12-12 12:24

    From v0.11+, ... use df.iloc.

    In [7]: df.iloc[:,0]
    Out[7]: 
    0    1
    1    2
    2    3
    3    4
    Name: x, dtype: int64
    

提交回复
热议问题