Pandas scatter_matrix - plot categorical variables

后端 未结 3 956
谎友^
谎友^ 2021-02-09 05:19

I am looking at the famous Titanic dataset from the Kaggle competition found here: http://www.kaggle.com/c/titanic-gettingStarted/data

I have loaded and processed the da

3条回答
  •  旧时难觅i
    2021-02-09 05:58

    after googling and remembering something like the .map() function I fixed it in the following way:

    colors=['red','green'] # color codes for survived : 0=red or 1=green
    
    # create mapping Series for gender so it can be plotted
    gender = Series([0,1],index=['male','female'])    
    df['gender']=df.Sex.map(gender)
    
    # create mapping Series for Embarked so it can be plotted
    embarked = Series([0,1,2,3],index=df.Embarked.unique())
    df['embarked']=df.Embarked.map(embarked)
    
    # add survived also back to the df
    df['survived']=target
    

    now I can plot it again...and drop the added columns afterwards.

    thanks everyone for responding.....

提交回复
热议问题