Challenge: Violin and Swarm Plots (Part 2)
Oppgave
Swipe to start coding
This task is similar to the previous one. You need to plot the graphs for the 'Earning'
columns and conclude: are the variances different?
- Concatenate the dataframes.
- Build the violin plots.
- Build the swarm plots.
Løsning
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
33
#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='Earning', color="r", alpha=0.8)
#Plotting swarm plots
sns.swarmplot(data=df_combined, x='group', y='Earning', palette=colors_list)
#Sign the axes
plt.xlabel('')
plt.ylabel('Earning')
plt.title('Comparison of Earning')
#Show the results
plt.show()
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 3
single
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
33
# 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.___([df_control, df_test])
# Plotting violin plots
sns.___(data=df_combined, x='group', y='Earning', color="r", alpha=0.8)
#Plotting swarm plots
sns.___(data=df_combined, x='group', y='Earning', palette=colors_list)
# Sign the axes
plt.xlabel('')
plt.ylabel('Earning')
plt.title('Comparison of Earning')
# Show the results
plt.show()
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår