<jupyter_start><jupyter_text>Tips  Introduction:This exercise was created based on the tutorial and documentation from [Seaborn](https://stanford.edu/~mwaskom/software/seaborn/index.html)  The dataset being used is tips from Seaborn. Step 1. Import the necessary libraries:<jupyter_code>import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/07_Visualization/Tips/tips.csv).   Step 3. Assign it to a variable called tips<jupyter_code>url = 'https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/07_Visualization/Tips/tips.csv'

tips = pd.read_csv(url, index_col=0)
tips.reset_index()
tips<jupyter_output><empty_output><jupyter_text>Step 4. Delete the Unnamed 0 column<jupyter_code># already done<jupyter_output><empty_output><jupyter_text>Step 5. Plot the total_bill column histogram<jupyter_code>sns.set(style='white')
sns.set_context(rc = {'patch.linewidth': 2.0})

ax = sns.histplot(tips['total_bill'], kde=True, stat='density')
ax.set(xlabel='Value', ylabel='Frequency')
ax.set_title('Total Bill', size=15)

sns.despine();
# Original solution:

# create histogram
ttbill = sns.distplot(tips.total_bill);

# set lables and titles
ttbill.set(xlabel = 'Value', ylabel = 'Frequency', title = "Total Bill")

# take out the right and upper borders
sns.despine()<jupyter_output>/anaconda3/lib/python3.7/site-packages/seaborn/distributions.py:2551: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)<jupyter_text>Step 6. Create a scatter plot presenting the relationship between total_bill and tip<jupyter_code>sns.jointplot(x=tips['total_bill'], y=tips['tip'], xlim=(0, 60), ylim=(0, 12));<jupyter_output><empty_output><jupyter_text>Step 7.  Create one image with the relationship of total_bill, tip and size. Hint: It is just one function.<jupyter_code>sns.pairplot(data=tips[['total_bill', 'tip', 'size']]);

# Original solution:
#
# sns.pairplot(tips)<jupyter_output><empty_output><jupyter_text>Step 8. Present the relationship between days and total_bill value<jupyter_code>sns.set_style('whitegrid')
plt.figure(figsize=(8, 6))
ax = sns.stripplot(x=tips['day'], y=tips['total_bill'])
ax.set_ylim(0, 60);

# Original solution:
#
# sns.stripplot(x = "day", y = "total_bill", data = tips, jitter = True);
# What a "jitter" is (for demonstration purposes):
sns.stripplot(x = "day", y = "total_bill", data = tips, jitter = 0.4);<jupyter_output><empty_output><jupyter_text>Step 9. Create a scatter plot with the day as the y-axis and tip as the x-axis, differ the dots by sex<jupyter_code>sns.set_style("whitegrid")
plt.figure(figsize=(8, 6))

ax = sns.scatterplot(data=tips, x='tip', y='day', hue='sex');
ax.yaxis.grid(False)
ax.legend(title='Sex', framealpha = 1, edgecolor='w');

# Original solution:
#
# sns.stripplot(x = "tip", y = "day", hue = "sex", data = tips, jitter = True);<jupyter_output><empty_output><jupyter_text>Step 10.  Create a box plot presenting the total_bill per day differetiation the time (Dinner or Lunch)<jupyter_code>plt.figure(figsize=(12, 6))
sns.boxplot(data=tips, x='day', y='total_bill', hue='time');<jupyter_output><empty_output><jupyter_text>Step 11. Create two histograms of the tip value based for Dinner and Lunch. They must be side by side.<jupyter_code>sns.set_style('ticks')
g = sns.FacetGrid(data=tips, col='time')
g.map(sns.histplot, 'tip', bins=10)
g.set(xlim=(0, 12), ylim=(0, 60), xticks=range(0, 13, 2), yticks=range(0, 61, 10));
sns.despine();

# Original solution:
#
# # better seaborn style
# sns.set(style = "ticks")
# # creates FacetGrid
# g = sns.FacetGrid(tips, col = "time")
# g.map(plt.hist, "tip");<jupyter_output><empty_output><jupyter_text>Step 12. Create two scatterplots graphs, one for Male and another for Female, presenting the total_bill value and tip relationship, differing by smoker or no smoker They must be side by side.<jupyter_code>g = sns.FacetGrid(data=tips, col='sex')
g.map_dataframe(sns.scatterplot, x='total_bill', y='tip', hue='smoker')
g.add_legend(title='Smoker')
g.set_axis_labels('Total bill', 'Tip')
g.set(xlim=(0, 60), ylim=(0, 12), xticks=range(0, 61, 10), yticks=range(0, 13, 2));


# Original solution:
#
# g = sns.FacetGrid(tips, col = "sex", hue = "smoker")
# g.map(plt.scatter, "total_bill", "tip", alpha =.7)
# g.add_legend();<jupyter_output><empty_output><jupyter_text>BONUS: Create your own question and answer it using a graph.<jupyter_code>g = sns.FacetGrid(data=tips, col='sex')
g.map(sns.kdeplot, 'total_bill');
sns.kdeplot(tips['total_bill'], hue=tips['sex']);
sns.histplot(data=tips, x='total_bill', hue='sex');
tips.groupby('sex')[['total_bill']].sum()
tips.groupby('sex')[['total_bill']].count()
males = tips[tips['sex'] == 'Male'].sample(87)
males.head()
females = tips[tips['sex'] == 'Female']
females.head()
new_tips = pd.concat([males, females]).reset_index()
new_tips.head()
sns.kdeplot(data=new_tips, x='total_bill', hue='sex');
sns.histplot(data=new_tips, x='total_bill', hue='sex');
g = sns.FacetGrid(data=new_tips, col='sex')
g.map(sns.scatterplot, 'total_bill', 'tip');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1576136991345977, 'fraction_numerical': 0.015835021174737618, 'mean_word_length': 6.90684133915575, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 3, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '1735', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2023, 'n_words': 457, 'path': '07_Visualization/Tips/Exercises.ipynb', 'repo_name': 'alexkataev/pandas_exercises', 'size': '5431'}