男人和女人在标有“性别”的栏中。我想根据他们的幸福水平来画它们。 因此,一图两列一行。
我尝试提取每种性别:
=IF(ROWS(B$13:B13)<=$B$10,INDEX($A$2:$A$7,SMALL(IF(MMULT(IF(LEFT($B$2:$G$7,LEN($A$13))=$A$13,1,0),TRANSPOSE(COLUMN($B$2:$G$7))^0)>0,ROW($A$2:$A$7)-ROW($A$2)+1),ROWS(B$13:B13))),"")
答案 0 :(得分:1)
import pandas as pd
import matplotlib.pyplot as plt # doesn't have color by hue
import seaborn as sns
import numpy as np # for generating random data
import random # for random gender selection
df = pd.DataFrame({'age': [x for x in np.random.randint(20, 70, 100)],
'feeling': [random.choice(['happy', 'sad']) for _ in range(100)],
'gender': [random.choice(['male', 'female']) for _ in range(100)]})
sns.boxplot(y='age', x='feeling', data=df, hue='gender')
plt.show()
groupby
与分类数据一起使用:df = pd.DataFrame({'feeling': [random.choice(['happy', 'sad|']) for _ in range(100)],
'gender': [random.choice(['male', 'female']) for _ in range(100)]})
df.groupby(['feeling','gender'])['gender'].count().plot(kind='bar')
feeling
作为数值:df = pd.DataFrame({'feeling': [x for x in np.random.randint(0, 101, 100)],
'gender': [random.choice(['male', 'female']) for _ in range(100)]})
plt.figure(figsize=(8, 7))
sns.boxplot(y='feeling', x='gender', data=df)
plt.show()
答案 1 :(得分:0)
import pandas as pd
import matplotlib.pyplot as plt
我已经为您的数据框创建了一个虚构的样本。
data = [['men', 55], ['men', 77], ['women', 85],
['men', 70], ['women', 68], ['women', 64],
['men', 86], ['men', 64], ['women', 54],
['men', 43], ['women', 86], ['women', 91]]
df = pd.DataFrame(data, columns = ['sex', 'happy'])
您可以:
df.boxplot(by=['sex'], sym ='', figsize = [6, 6])
它产生: 我想这就是您想要的。