Desafío: Violín y Gráficos de Enjambre (Parte 1)
Tarea
Swipe to start coding
En esta tarea, usted necesita construir un violin y un swarm plot en el mismo lienzo. Estos gráficos deben construirse para la columna 'Compra'
. Compare las varianzas: ¿son similares?
-
- Importe las bibliotecas.
- Concatene los marcos de datos.
- Construya las parcelas de violín.
-
- Construir los plots de enjambre.
Solución
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Import libraries
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# Read .csv files
df_control = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c3b98ad3-420d-403f-908d-6ab8facc3e28/ab_control.csv', delimiter=';')
df_test = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c3b98ad3-420d-403f-908d-6ab8facc3e28/ab_test.csv', delimiter=';')
# Define colors for graphs
colors_list = ['#ff8a00', '#33435c']
# Add to the dataframes columns-labels, which mean belonging to either the control or the test group
df_control['group'] = 'Contol group'
df_test['group'] = 'Test group'
# Concat control and test dataframes
df_combined = pd.concat([df_control, df_test])
# Plotting violin plots
sns.violinplot(data=df_combined, x='group', y='Purchase', color="r", alpha=0.8)
# Plotting swarm plots
sns.swarmplot(data=df_combined, x='group', y='Purchase', palette=colors_list)
# Sign the axes
plt.xlabel('')
plt.ylabel('Purchase')
plt.title('Comparison of Purchase')
# Show the results
plt.show()
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 3. Capítulo 2
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Import libraries
___ ___ as plt
___ ___ as pd
___ ___ as sns
# Read .csv files
df_control = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c3b98ad3-420d-403f-908d-6ab8facc3e28/ab_control.csv', delimiter=';')
df_test = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c3b98ad3-420d-403f-908d-6ab8facc3e28/ab_test.csv', delimiter=';')
# Define colors for graphs
colors_list = ['#ff8a00', '#33435c']
# Add to the dataframes columns-labels, which mean belonging to either the control or the test group
df_control['group'] = 'Contol group'
df_test['group'] = 'Test group'
# Concat control and test dataframes
df_combined = pd.___([___, ___])
# Plotting violin plots
sns.___(data=df_combined, x='group', y='Purchase', color="r", alpha=0.8)
# Plotting swarm plots
sns.___(data=df_combined, x='group', y='Purchase', palette=colors_list)
# Sign the axes
plt.xlabel('')
plt.ylabel('Purchase')
plt.title('Comparison of Purchase')
# Show the results
plt.show()
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla