Plot multiple columns of Pandas DataFrame using Seaborn

后端 未结 2 1408
独厮守ぢ
独厮守ぢ 2020-12-08 20:53

suppose I have DataFrame with columns [\'X_Axis\',\'col_2\',\'col_3\',...,\'col_n\',]

I need to plot the first column on X-Axis and rest on Y-Axis. FYI

2条回答
  •  [愿得一人]
    2020-12-08 21:25

    in addition to mighty @jezrael for those who come from google if you intend to plot lines with the index of the original dataframe just do as follows:

    df = pd.DataFrame({'col_2':[.4,.5,.4,.5,.5,.4],
                       'col_3':[.7,.8,.9,.4,.2,.3],
                       'col_4':[.1,.3,.5,.7,.1,.0],
                       'col_5':[.5,.3,.6,.9,.2,.4]})
    
    # resetting index before melting to save the current index in 'index' column...
    df = df.reset_index().melt('index', var_name='cols',  value_name='vals')
    g = sns.catplot(x="index", y="vals", hue='cols', data=df, kind='point')
    

提交回复
热议问题