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

前端 未结 6 1519
花落未央
花落未央 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:19

    df[df.columns[i]]
    

    where i is the position/number of the column(starting from 0).

    So, i = 0 is for the first column.

    You can also get the last column using i = -1

提交回复
热议问题