Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Add Audio.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/01.03-Magic-Commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The previous two sections showed how IPython lets you use and explore Python efficiently and interactively.\n",
"This is a test for the special character ñ in markdown cell. The previous two sections showed how IPython lets you use and explore Python efficiently and interactively.\n",
"Here we'll begin discussing some of the enhancements that IPython adds on top of the normal Python syntax.\n",
"These are known in IPython as *magic commands*, and are prefixed by the ``%`` character.\n",
"These magic commands are designed to succinctly solve various common problems in standard data analysis.\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/02.00-Introduction-to-NumPy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
204 changes: 192 additions & 12 deletions notebooks/04.14-Visualization-With-Seaborn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
"source": [
"<!--BOOK_INFORMATION-->\n",
"<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PDSH-cover-small.png\">\n",
"*This notebook contains an excerpt from the [Python Data Science Handbook](http://shop.oreilly.com/product/0636920034919.do) by Jake VanderPlas; the content is available [on GitHub](https://github.com/jakevdp/PythonDataScienceHandbook).*\n",
"*This notebook contains an excerpt from the [Python Data Science Handbook] (random addition) (http://shop.oreilly.com/product/0636920034919.do) by Jake VanderPlas; the content is available [on GitHub](https://github.com/jakevdp/PythonDataScienceHandbook).*\n",
"\n",
"**Changing Header and first row completely**\n",
"\n",
"| Change | header and | 1st | row | completely | for testing |\n",
"|----------|-------------|------|----------|-------------|------|\n",
"| the | colons | after | the header | row are | removed |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace\n",
"\n",
"*The text is released under the [CC-BY-NC-ND license](https://creativecommons.org/licenses/by-nc-nd/3.0/us/legalcode), and code is released under the [MIT license](https://opensource.org/licenses/MIT). If you find this content useful, please consider supporting the work by [buying the book](http://shop.oreilly.com/product/0636920034919.do)!*"
]
Expand All @@ -16,7 +27,18 @@
"metadata": {},
"source": [
"<!--NAVIGATION-->\n",
"< [Geographic Data with Basemap](04.13-Geographic-Data-With-Basemap.ipynb) | [Contents](Index.ipynb) | [Further Resources](04.15-Further-Resources.ipynb) >"
"< [Geographic Data with Basemap](04.13-Geographic-Data-With-Basemap.ipynb) | [Contents](Index.ipynb) | [Further Resources](04.15-Further-Resources.ipynb) >\n",
"\n",
"**Additional Column in the middle**\n",
"\n",
"| Tables | Are | Cool | NEW COLUMN | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | ADDING A | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | COLUMN | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | FOR THE | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | TESTING | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | PURPOSE | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | HERE ON OUT | Let's make | world a better place | peace"
]
},
{
Expand All @@ -33,6 +55,17 @@
"Matplotlib has proven to be an incredibly useful and popular visualization tool, but even avid users will admit it often leaves much to be desired.\n",
"There are several valid complaints about Matplotlib that often come up:\n",
"\n",
"**Small changes at multiple places**\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | right aligned | 1800 | Still some | work got to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| row 2 is | centered | 12 | but it is 2220 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world A better place | apple pie\n",
"\n",
"- Prior to version 2.0, Matplotlib's defaults are not exactly the best choices. It was based off of MATLAB circa 1999, and this often shows.\n",
"- Matplotlib's API is relatively low level. Doing sophisticated statistical visualization is possible, but often requires a *lot* of boilerplate code.\n",
"- Matplotlib predated Pandas by more than a decade, and thus is not designed for use with Pandas ``DataFrame``s. In order to visualize data from a Pandas ``DataFrame``, you must extract each ``Series`` and often concatenate them together into the right format. It would be nicer to have a plotting library that can intelligently use the ``DataFrame`` labels in a plot.\n",
Expand All @@ -51,7 +84,18 @@
"## Seaborn Versus Matplotlib\n",
"\n",
"Here is an example of a simple random-walk plot in Matplotlib, using its classic plot formatting and colors.\n",
"We start with the typical imports:"
"We start with the typical imports:\n",
"\n",
"**Remove 1st Column**\n",
"\n",
"Are | Cool | Let us | test them | properly, shall we? |\n",
"-------------:|:------:|:----------:|:-------------:|:------:|\n",
" left aligned | 1600 | Still some | work to | be done |\n",
" centered | 12 | to fix | all the changes | in the table properly |\n",
" right aligned | 1 | hence, we are testing | the table changes | here |\n",
" left aligned | 1600 | It's weird | to write random | text\n",
" centered | 12 | but it's 2020 | and I got | to do this | \n",
" right aligned | 1 | Let's make | world a better place | peace"
]
},
{
Expand All @@ -71,7 +115,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we create some random walk data:"
"**First and last row removed**\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | "
]
},
{
Expand Down Expand Up @@ -121,6 +172,18 @@
"source": [
"Although the result contains all the information we'd like it to convey, it does so in a way that is not all that aesthetically pleasing, and even looks a bit old-fashioned in the context of 21st-century data visualization.\n",
"\n",
"**ADD ROW IN MIDDLE**\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| COL NEW | NEWLY ADDED | COLUMN | 2200 | TO THIS TABLE | IN THE MIDDLE |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace\n",
"\n",
"Now let's take a look at how it works with Seaborn.\n",
"As we will see, Seaborn has many of its own high-level plotting routines, but it can also overwrite Matplotlib's default parameters and in turn get even simple Matplotlib scripts to produce vastly superior output.\n",
"We can set the style by calling Seaborn's ``set()`` method.\n",
Expand Down Expand Up @@ -173,6 +236,18 @@
"Ah, much better!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**DELETE TOP 2 AND BOTTOM 2 ROWS**\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -181,6 +256,17 @@
"\n",
"The main idea of Seaborn is that it provides high-level commands to create a variety of plot types useful for statistical data exploration, and even some statistical model fitting.\n",
"\n",
"**DELETE FIRST 2 AND LAST 2 COLUMNS**\n",
"\n",
"| Cool | Let us |\n",
"|:------:|:----------:|\n",
"| 1600 | Still some |\n",
"| 12 | to fix |\n",
"| 1 | hence, we are testing |\n",
"| 1600 | It's weird |\n",
"| 12 | but it's 2020 |\n",
"| 1 | Let's make |\n",
"\n",
"Let's take a look at a few of the datasets and plot types available in Seaborn. Note that all of the following *could* be done using raw Matplotlib commands (this is, in fact, what Seaborn does under the hood) but the Seaborn API is much more convenient."
]
},
Expand All @@ -191,7 +277,14 @@
"### Histograms, KDE, and densities\n",
"\n",
"Often in statistical data visualization, all you want is to plot histograms and joint distributions of variables.\n",
"We have seen that this is relatively straightforward in Matplotlib:"
"We have seen that this is relatively straightforward in Matplotlib:\n",
"\n",
"**REPLACE ENTIRE TABLE**\n",
"\n",
"Markdown | Less | Pretty\n",
"--- | --- | ---\n",
"*Still* | `renders` | **nicely**\n",
"1 | 2 | 3"
]
},
{
Expand Down Expand Up @@ -251,7 +344,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Histograms and KDE can be combined using ``distplot``:"
"Histograms and KDE can be combined using ``distplot``:\n",
"\n",
"**NEW ROW AT END**\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace\n",
"| NEWLY | ADDED | ROW | AT THE | END OF THE | TABLE"
]
},
{
Expand Down Expand Up @@ -279,6 +384,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**REMOVE LAST COLUMN**\n",
"\n",
"| Tables | Are | Cool | Let us | test them |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to |\n",
"| col 2 is | centered | 12 | to fix | all the changes |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random |\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got |\n",
"| col 3 is | right aligned | 1 | Let's make | world a better place |\n",
"\n",
"\n",
"If we pass the full two-dimensional dataset to ``kdeplot``, we will get a two-dimensional visualization of the data:"
]
},
Expand Down Expand Up @@ -307,7 +424,16 @@
"metadata": {},
"source": [
"We can see the joint distribution and the marginal distributions together using ``sns.jointplot``.\n",
"For this plot, we'll set the style to a white background:"
"For this plot, we'll set the style to a white background:\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace"
]
},
{
Expand Down Expand Up @@ -335,7 +461,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There are other parameters that can be passed to ``jointplot``—for example, we can use a hexagonally based histogram instead:"
"There are other parameters that can be passed to ``jointplot``—for example, we can use a hexagonally based histogram instead:\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace"
]
},
{
Expand Down Expand Up @@ -374,7 +509,16 @@
{
"cell_type": "markdown",
"metadata": {},
"source": []
"source": [
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace"
]
},
{
"cell_type": "code",
Expand All @@ -389,6 +533,15 @@
"source": [
"### Faceted histograms\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace\n",
"\n",
"Emptied above cells Sometimes the best way to view data is via histograms of subsets. Seaborn's ``FacetGrid`` makes this extremely simple.\n",
"We'll take a look at some data that shows the amount that restaurant staff receive in tips based on various indicator data:"
]
Expand Down Expand Up @@ -518,7 +671,16 @@
"source": [
"### Factor plots\n",
"\n",
"Factor plots can be useful for this kind of visualization as well. This allows you to view the distribution of a parameter within bins defined by any other parameter:"
"Factor plots can be useful for this kind of visualization as well. This allows you to view the distribution of a parameter within bins defined by any other parameter:\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace"
]
},
{
Expand Down Expand Up @@ -549,6 +711,15 @@
"source": [
"### Joint distributions\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace\n",
"\n",
"Similar to the pairplot we saw earlier, we can use ``sns.jointplot`` to show the joint distribution between different datasets, along with the associated marginal distributions:"
]
},
Expand Down Expand Up @@ -606,7 +777,16 @@
"source": [
"### Bar plots\n",
"\n",
"Time series can be plotted using ``sns.factorplot``. In the following example, we'll use the Planets data that we first saw in [Aggregation and Grouping](03.08-Aggregation-and-Grouping.ipynb):"
"Time series can be plotted using ``sns.factorplot``. In the following example, we'll use the Planets data that we first saw in [Aggregation and Grouping](03.08-Aggregation-and-Grouping.ipynb):\n",
"\n",
"| Tables | Are | Cool | Let us | test them | properly, shall we? |\n",
"|:----------:|:-------------:|:------:|:----------:|:-------------:|:------:|\n",
"| col 1 is | left aligned | 1600 | Still some | work to | be done |\n",
"| col 2 is | centered | 12 | to fix | all the changes | in the table properly |\n",
"| col 3 is | right aligned | 1 | hence, we are testing | the table changes | here |\n",
"| col 1 is | left aligned | 1600 | It's weird | to write random | text\n",
"| col 2 is | centered | 12 | but it's 2020 | and I got | to do this | \n",
"| col 3 is | right aligned | 1 | Let's make | world a better place | peace"
]
},
{
Expand Down Expand Up @@ -1611,7 +1791,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Loading