<jupyter_start><jupyter_text>_Lambda School Data Science_ Choose appropriate visualizations  Upgrade SeabornMake sure you have at least version 0.9.0<jupyter_code>!pip install --upgrade seaborn
import seaborn as sns
sns.__version__<jupyter_output><empty_output><jupyter_text>Fix misleading visualizations<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
!wget https://raw.githubusercontent.com/LambdaSchool/DS-Sprint-02-Storytelling-With-Data/master/module2-choose-appropriate-visualizations/misleading.py
    
import misleading<jupyter_output>--2018-11-13 21:40:15--  https://raw.githubusercontent.com/LambdaSchool/DS-Sprint-02-Storytelling-With-Data/master/module2-choose-appropriate-visualizations/misleading.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 172.16.17.32, 172.16.17.32, 192.168.127.12, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|172.16.17.32|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1641 (1.6K) [text/plain]
Saving to: ‘misleading.py.3’


misleading.py.3       0%[                    ]       0  --.-KB/s               
misleading.py.3     100%[===================>]   1.60K  --.-KB/s    in 0s      

2018-11-13 21:40:15 (182 MB/s) - ‘misleading.py.3’ saved [1641/1641]<jupyter_text>Fix misleading plot 1<jupyter_code>misleading.plot1()<jupyter_output><empty_output><jupyter_text>Fix misleading plot 2<jupyter_code>misleading.plot2()<jupyter_output><empty_output><jupyter_text>Fix misleading plot 3<jupyter_code>misleading.plot3()<jupyter_output><empty_output><jupyter_text>Fix misleading plot 4 _If you're on Jupyter (not Colab) then uncomment and run this cell below:_<jupyter_code># import altair as alt
# alt.renderers.enable('notebook')
misleading.plot4()<jupyter_output><empty_output><jupyter_text>Links- [How to Spot Visualization Lies](https://flowingdata.com/2017/02/09/how-to-spot-visualization-lies/)- [Where to Start and End Your Y-Axis Scale](http://stephanieevergreen.com/y-axis/)- [xkcd heatmap](https://xkcd.com/1138/)- [Surprise Maps: Showing the Unexpected](https://medium.com/@uwdata/surprise-maps-showing-the-unexpected-e92b67398865)  Use Seaborn to visualize distributions and relationships with continuous and discrete variables Links- [Seaborn tutorial](https://seaborn.pydata.org/tutorial.html)- [Seaborn example gallery](https://seaborn.pydata.org/examples/index.html)- [Chart Chooser](https://extremepresentation.typepad.com/files/choosing-a-good-chart-09.pdf)  1. Anscombe dataset  Load dataset<jupyter_code>df = sns.load_dataset('anscombe')<jupyter_output><empty_output><jupyter_text>See the data's shape<jupyter_code><jupyter_output><empty_output><jupyter_text>See the data<jupyter_code><jupyter_output><empty_output><jupyter_text>[Group by](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html) `'dataset'`<jupyter_code><jupyter_output><empty_output><jupyter_text>[Describe](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html) the groups<jupyter_code><jupyter_output><empty_output><jupyter_text>Get the [count](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.count.html), for each column in each group<jupyter_code><jupyter_output><empty_output><jupyter_text>Get the [mean](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.mean.html) ...<jupyter_code><jupyter_output><empty_output><jupyter_text>Get the [standard deviation](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.std.html) ...<jupyter_code><jupyter_output><empty_output><jupyter_text>Get the [correlation](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.corr.html) ...<jupyter_code><jupyter_output><empty_output><jupyter_text>Use pandas to [plot](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html) the groups, as scatter plots<jupyter_code><jupyter_output><empty_output><jupyter_text>Use Seaborn to make [relational plots](http://seaborn.pydata.org/generated/seaborn.relplot.html)<jupyter_code><jupyter_output><empty_output><jupyter_text>Use Seaborn to make [linear model plots](http://seaborn.pydata.org/generated/seaborn.lmplot.html)<jupyter_code><jupyter_output><empty_output><jupyter_text>Links- [Seaborn examples: Anscombe's quartet](http://seaborn.pydata.org/examples/anscombes_quartet.html)- [Wikipedia: Anscombe's quartet](https://en.wikipedia.org/wiki/Anscombe%27s_quartet)- [The Datasaurus Dozen](https://www.autodeskresearch.com/publications/samestats)  2. Tips dataset  Load dataset<jupyter_code>tips = sns.load_dataset('tips')<jupyter_output><empty_output><jupyter_text>See the data's shape<jupyter_code><jupyter_output><empty_output><jupyter_text>See the first 5 rows<jupyter_code><jupyter_output><empty_output><jupyter_text>Describe the data<jupyter_code><jupyter_output><empty_output><jupyter_text>Make univariate [distribution plots](https://seaborn.pydata.org/generated/seaborn.distplot.html)<jupyter_code><jupyter_output><empty_output><jupyter_text>Make bivariate [relational plots](https://seaborn.pydata.org/generated/seaborn.relplot.html)<jupyter_code><jupyter_output><empty_output><jupyter_text>Make univariate [categorical plots](https://seaborn.pydata.org/generated/seaborn.catplot.html)<jupyter_code><jupyter_output><empty_output><jupyter_text>Make bivariate [categorical plots](https://seaborn.pydata.org/generated/seaborn.catplot.html)<jupyter_code><jupyter_output><empty_output><jupyter_text>3. Flights<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Load dataset<jupyter_code>flights = sns.load_dataset('flights')<jupyter_output><empty_output><jupyter_text>See the data's shape<jupyter_code>flights.shape<jupyter_output><empty_output><jupyter_text>See the first 5 rows<jupyter_code>flights.head()<jupyter_output><empty_output><jupyter_text>Describe the data<jupyter_code>flights.describe()
flights.describe(exclude=np.number)<jupyter_output><empty_output><jupyter_text>Plot year & passengers<jupyter_code>sns.relplot('year','passengers',data=flights)
sns.catplot('year','passengers',data=flights,kind='box')
help(sns.catplot)<jupyter_output>Help on function catplot in module seaborn.categorical:

catplot(x=None, y=None, hue=None, data=None, row=None, col=None, col_wrap=None, estimator=<function mean at 0x7f4830f15510>, ci=95, n_boot=1000, units=None, order=None, hue_order=None, row_order=None, col_order=None, kind='strip', height=5, aspect=1, orient=None, color=None, palette=None, legend=True, legend_out=True, sharex=True, sharey=True, margin_titles=False, facet_kws=None, **kwargs)
    Figure-level interface for drawing categorical plots onto a FacetGrid.
    
    This function provides access to several axes-level functions that
    show the relationship between a numerical and one or more categorical
    variables using one of several visual representations. The ``kind``
    parameter selects the underlying axes-level function to use:
    
    Categorical scatterplots:
    
    - :func:`stripplot` (with ``kind="strip"``; the default)
    - :func:`swarmplot` (with ``kind="swarm"``)
    
    Categorical distribution plots[...]<jupyter_text>Plot month & passengers<jupyter_code>sns.catplot('passengers', 'month',data=flights,kind='bar')<jupyter_output><empty_output><jupyter_text>Create a [pivot table](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot_table.html) of passengers by month and year<jupyter_code>ptable = flights.pivot_table('passengers','year','month')
#ptable = flights.pivot_table(values=['passengers'],index=['month'],columns='year',aggfunc=np.sum)
#ptable = flights.pivot_table(values=['passengers'],index=['month','year'],aggfunc=np.sum)
print(ptable)<jupyter_output>month  January  February  March  April  May  June  July  August  September  \
year                                                                         
1949       112       118    132    129  121   135   148     148        136   
1950       115       126    141    135  125   149   170     170        158   
1951       145       150    178    163  172   178   199     199        184   
1952       171       180    193    181  183   218   230     242        209   
1953       196       196    236    235  229   243   264     272        237   
1954       204       188    235    227  234   264   302     293        259   
1955       242       233    267    269  270   315   364     347        312   
1956       284       277    317    313  318   374   413     405        355   
1957       315       301    356    348  355   422   465     467        404   
1958       340       318    362    348  363   435   491     505        404   
1959       360       342    406    396  420   472   548     559 [...]<jupyter_text>Plot the pivot table as a [heat map](https://seaborn.pydata.org/generated/seaborn.heatmap.html)<jupyter_code>yticklabels=[x for x in range(1949,1961)]
sns.heatmap(ptable);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12305656632484287, 'fraction_numerical': 0.05678685632374021, 'mean_word_length': 4.874352331606218, 'pattern_counts': {'":': 0, '<': 139, '<?xml version=': 0, '>': 140, 'https://': 23, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '35', 'dir': 'jupyter-structured-clean-dedup', 'id': '146553', 'license': 'MIT', 'n_tokens_mistral': 3564, 'n_tokens_neox': 3119, 'n_words': 517, 'path': 'module2-choose-appropriate-visualizations/LS_DS_122_Choose_appropriate_visualizations.ipynb', 'repo_name': 'ShreyasJothish/DS-Sprint-02-Storytelling-With-Data', 'size': '9074'}