How to convert a single column Pandas DataFrame into Series

后端 未结 3 1529
-上瘾入骨i
-上瘾入骨i 2020-12-19 07:21

I have the following data frame:

import pandas as pd
d = {\'gene\' : [\'foo\',\'bar\'],\'score\' : [4., 3.,]}
df = pd.DataFrame(d)
df.set_index(\'gene\',inpl         


        
3条回答
  •  借酒劲吻你
    2020-12-19 08:00

    Swapping the indices would solve the problem easily:

    In [64]: type(df.iloc[0:,])
    Out[64]: pandas.core.frame.DataFrame
    
    In [65]: df.iloc[[:,0] // Swaped the indices
    Out[65]:
            score
    gene
    foo       4
    bar       3
    

提交回复
热议问题