Countplot()#
0:00 min | Última modificación: Octubre 12, 2021 | [YouTube]
[1]:
import matplotlib.pyplot as plt
import seaborn as sns
[2]:
tips = sns.load_dataset("tips")
display(
tips.head(),
tips.tail(),
tips.size,
)
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
239 | 29.03 | 5.92 | Male | No | Sat | Dinner | 3 |
240 | 27.18 | 2.00 | Female | Yes | Sat | Dinner | 2 |
241 | 22.67 | 2.00 | Male | Yes | Sat | Dinner | 2 |
242 | 17.82 | 1.75 | Male | No | Sat | Dinner | 2 |
243 | 18.78 | 3.00 | Female | No | Thur | Dinner | 2 |
1708
[3]:
#
# Gráfico básico de conteo por categoría
#
sns.countplot(
x="smoker",
data=tips,
)
plt.show()
[4]:
#
# Separación por una categoría adicional
#
palette = {
"Female": "blue",
"Male": "red",
}
sns.countplot(
x="smoker",
hue="sex",
palette=palette,
data=tips,
)
plt.show()