<jupyter_start><jupyter_text>Data Visualization![image](front.png) We'll start by importing standard packages: 'pandas', 'seaborn', or 'matplotlib'<jupyter_code>import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Get a sample datasetHere we'll take advantage of built-in dataset 'iris'<jupyter_code>df = sns.load_dataset('iris')
df<jupyter_output><empty_output><jupyter_text>Box Plots vs Violin Plots  Store all variables to a list<jupyter_code>vars = df.columns.values.tolist()
vars<jupyter_output><empty_output><jupyter_text>Box Plot<jupyter_code># make a box plot of the iris species
sns.boxplot(y=vars[0], data=df)
plt.show()
# set a grey background color
sns.set_style("darkgrid")
# and create the box plot again to see the difference
sns.boxplot(y=vars[0], data=df)
plt.show()<jupyter_output><empty_output><jupyter_text>Although visualizing all sepal lengths can be useful, grouping by species may allow for a better assessment of the data.<jupyter_code>sns.boxplot(x='species', y=df[vars[0]], data=df)
plt.ylabel(vars[0])
plt.show()<jupyter_output><empty_output><jupyter_text>**Boxplots** allow for a overall perception of the distribution: Median, quartiles, or outliers will be easily identified.Nevertheless, the underlying distribution will be hidden, as well as the number of observations in the dataset, which may, in some cases, impair our ability to draw conclusions.To overcome this limitation, adding a stripplot may be a good  choice.<jupyter_code># add stripplot to the box plot
sns.boxplot(x='species', y=df[vars[0]], data=df)
plt.ylabel(vars[0])
sns.stripplot(x='species', y=df[vars[0]], data=df, jitter=True, size=3, color='black') # color black allow to see the difference
plt.show()<jupyter_output><empty_output><jupyter_text>An even better alternative to show the data distribution is to use a violin plot instead of a box plot  Violin Plot<jupyter_code>#make a violin plot of all rows in a dataframe column
sns.violinplot(y=df[vars[0]])
#set up y label
plt.ylabel(vars[0])
plt.show()
# Group variables by species
sns.violinplot(x='species', y=df[vars[0]], data=df)
plt.ylabel(vars[0])
plt.show()<jupyter_output><empty_output><jupyter_text>By data visualization, we can start drawing some conclusions. The first is that the three groups seem to have different distributions of septal lengths.**Remark**: further statistical assessment will be necessary to draw definite conclusions<jupyter_code>fig, axs = plt.subplots(1, len(vars)-1, figsize=(15,5))
for i in range(0,len(vars)-1):
    sns.violinplot(x='species', y=df[vars[i]], data=df,ax=axs[i])
    axs[i].set_ylabel(vars[i])

plt.show()<jupyter_output><empty_output><jupyter_text>Finally, let's look at the differences by putting boxplots and violinplots near to each other<jupyter_code>fig, axs = plt.subplots(2, len(vars)-1, figsize=(20,10))
for i in range(0,len(vars)-1):
    sns.violinplot(x='species', y=df[vars[i]], data=df,ax=axs[0,i])
    axs[0,i].set_ylabel(vars[i])
for i in range(0,len(vars)-1):
    sns.boxplot(x='species', y=df[vars[i]], data=df,ax=axs[1,i])
    axs[1,i].set_ylabel(vars[i])
    sns.stripplot(x='species', y=df[vars[i]], data=df, jitter=True, size=3, color='black', ax=axs[1,i])

plt.show()
fig.savefig('front.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13287134679120216, 'fraction_numerical': 0.010545344983428743, 'mean_word_length': 7.197530864197531, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '101638', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1176, 'n_words': 315, 'path': 'DataVisualization/ViolinPlot_vs_BoxPlot/ViolinPlot_vs_BoxPlot.ipynb', 'repo_name': 'econdesousa/portfolio', 'size': '3319'}