Challenge: Plotting Boxplots
Tehtävä
Swipe to start coding
In this task, you need to draw box plots of the 'Click'
columns for the control and test samples. Box plots are very informative graphs and are constantly used for visual analysis of data distribution.
- Import libraries.
- Read the files.
- Plot the boxplots.
Ratkaisu
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
# Import libraries
import pandas as pd
import matplotlib.pyplot as plt
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=';')
# We 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 the dataframes and plotting boxplots
df_combined = pd.concat([df_control, df_test])
sns.boxplot(data=df_combined, x='group', y='Click', palette=['#1e2635', '#ff8a00'],
medianprops={'color': 'red'})
# Sign the axes
plt.xlabel('')
plt.ylabel('Clicks')
plt.title('Comparison of Clicks')
# Show the results
plt.show()
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 2. Luku 6
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
# Import libraries
import ___ as pd
import ___ as plt
import ___ as sns
# Read .csv files
df_control = pd.___('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c3b98ad3-420d-403f-908d-6ab8facc3e28/ab_control.csv', delimiter=';')
df_test = pd.___('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c3b98ad3-420d-403f-908d-6ab8facc3e28/ab_test.csv', delimiter=';')
# We 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 the dataframes and plotting boxplots
df_combined = pd.concat([df_control, df_test])
sns___(data=___, x='group', y='Click', palette=['#1e2635', '#ff8a00'],
medianprops={'color': 'red'})
# Sign the axes
plt.xlabel('')
plt.ylabel('Clicks')
plt.title('Comparison of Clicks')
# Show the results
plt.show()
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme