How to use seaborn boxplot with dataframe has array value

Viewed 628

My data is a dataframe like below.

Each array in column 'Tx' is what I actually want to use as boxplot data, so it should get 4 boxes at the chart.

My request is to draw a boxplot chart, x label is 'part7', y is the value from 'Tx', and give each box color based on 'part'

This should be easily approach by seaborn boxplot, but in this case I can not get the result I wished.

#My dataframe
df = pd.DataFrame([['TMIG98','TMIG98AA','stage1','ABCD01',[0,0,10]],
                   ['TMIG98','TMIG98AB','stage1','ABCD01',[2,0,0,10]],
                   ['TMIG99','TMIG99AA','stage1','ABCD02',[0,6,2,0]],
                   ['TMIG99','TMIG99AB','stage1','ABCD02',[1,0,9]]],
                    columns=['part','part7','stage','tool','Tx'])

#When I used seaborn boxplot, it shows"ValueError: Could not interpret input part7'"
sns.boxplot(data=df['Tx'], x='part7', y='Tx', hue='part')

If I do not use the 'x', 'y', 'hue', it will generate a boxplot but not match my request

#If I do not use the 'x', 'y', 'hue'
sns.boxplot(data=df['Tx'])

The image without parameter 'x', 'y', 'hue'

My requests are:

  1. the x label should be 'TMIG98AA' / 'TMIG98AB' / 'TMIG99AA' / 'TMIG99AB'
  2. the box should only has two colors (one for 'TMIG98' and the other for 'TMIG99')

Can any one help me?? Thanks a lot!

1 Answers

What about using..

sns.boxplot(x='TMIG98AA', data=df)

OR as you are using in your code

sns.boxplot(x='part7', y='Tx', data=df, hue='part')

Related