Convert pandas data frame to series

后端 未结 6 1488
忘了有多久
忘了有多久 2020-11-30 21:52

I\'m somewhat new to pandas. I have a pandas data frame that is 1 row by 23 columns.

I want to convert this into a series? I\'m wondering what the most pythonic way

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 22:09

    Another way -

    Suppose myResult is the dataFrame that contains your data in the form of 1 col and 23 rows

    // label your columns by passing a list of names
    myResult.columns = ['firstCol']
    
    // fetch the column in this way, which will return you a series
    myResult = myResult['firstCol']
    
    print(type(myResult))
    

    In similar fashion, you can get series from Dataframe with multiple columns.

提交回复
热议问题