Seaborn boxplot: TypeError: unsupported operand type(s) for /: 'str' and 'int'

后端 未结 1 1984
名媛妹妹
名媛妹妹 2020-12-19 06:10

I try to make vertical seaborn boxplot like this

import pandas as pd
df = pd.DataFrame({\'a\' : [\'a\', \'b\' , \'b\', \'a\'], \'b\' : [5, 6, 4, 3] })
import         


        
相关标签:
1条回答
  • 2020-12-19 06:32

    For seaborn's boxplots it is important to keep an eye on the x-axis and y-axis assignments, when switching between horizontal and vertical alignment:

    %matplotlib inline
    import pandas as pd
    import seaborn as sns
    
    df = pd.DataFrame({'a' : ['a', 'b' , 'b', 'a'], 'b' : [5, 6, 4, 3] })
    
    # horizontal boxplots
    sns.boxplot(x="b", y="a", data=df, orient='h')
    
    # vertical boxplots
    sns.boxplot(x="a", y="b", data=df, orient='v')
    

    Mixing up the columns will cause seaborn to try to calculate the summary statistics of the boxes on categorial data, which is bound to fail.

    0 讨论(0)
提交回复
热议问题