Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Violin and Swarm Plots (Part 2) | Variances in A/B Testing
The Art of A/B Testing

book
Challenge: Violin and Swarm Plots (Part 2)

Uppgift

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?

  1. Concatenate the dataframes.
  2. Build the violin plots.
  3. Build the swarm plots.

Lösning

#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()

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 3
# 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()

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt