Plot data from pandas DataFrame, colour of points dependant on a column

前端 未结 3 1668
一整个雨季
一整个雨季 2021-01-21 09:32

I have a pandas DataFrame with 3 columns, shown below.

col1 value flag 1 0 0 2 0.03915 0 3 0.13 1

3条回答
  •  臣服心动
    2021-01-21 10:29

    Assuming the dataframe containing the given data is df, this is what you want. You can create a list of colors according to your condition flag column and its values. Feed that colors list to color argument in the built-in DataFrame.plot.scatter function. (You can find the docs here.)

    colors = ['r' if flag==1 else 'b' for flag in df.flag]
    df.plot.scatter('col1', 'value', color=colors)
    

    Hope this helps.

提交回复
热议问题