Skip to content

Commit 68523f9

Browse files
committed
fix typos
1 parent 8d689c9 commit 68523f9

File tree

9 files changed

+39
-36
lines changed

9 files changed

+39
-36
lines changed

.DS_Store

-2 KB
Binary file not shown.

_posts/2020-05-14-reshaping-data-in-python-pandas/reshaping-data-in-python-pandas.Rmd

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ knitr::opts_chunk$set(echo = TRUE, cache = FALSE, comment = NA, message = FALSE,
2727

2828
Get source code for this RMarkdown script [here](https://raw.githubusercontent.com/hauselin/rtutorialsite/master/_posts/2020-05-17-reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable/reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable.Rmd).
2929

30-
This Python tutorial is also available on [Medium, Towards Data Science](https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02). Click here if you're looking for the R version of melt (also the `melt` function in R).
30+
This Python tutorial is on [Medium, Towards Data Science](https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02). Click here if you're looking for the tutorial for the R version of melt (also the `melt` function in R).
3131

3232
## Consider being a patron and supporting my work?
3333

@@ -37,7 +37,7 @@ How does the pandas `melt()` method reshape dataframes? How do you reshape a dat
3737

3838
![Summary of how pd.melt() works](./main_wide2long.png)
3939

40-
Also, you might want to check out the official pandas documentation and my [numpy reshape tutorial](https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02).
40+
Also, you might want to check out the official pandas documentation and my [numpy reshape tutorial](https://towardsdatascience.com/reshaping-numpy-arrays-in-python-a-step-by-step-pictorial-tutorial-aed5f471cf0b?source=friends_link&sk=3dc229066e89cb5bcd4bb86b301f0a5c).
4141

4242
Let's load the `reticulate` library in R so we can run Python in RStudio. I'll then load my conda python environment. I highly recommend you try the code in Python while you read this article. Try running this tutorial on my shared [DeepNote notebook](https://beta.deepnote.com/project/d1350ad6-bcb4-4c3d-857b-c29d01b8a803) (you can only run but not edit this notebook).
4343

@@ -83,7 +83,7 @@ df_wide
8383

8484
Common terms for this transformation are melt, unpivot, gather, stack. See `pd.melt()` documentation [here](https://pandas.pydata.org/docs/reference/api/pandas.melt.html).
8585

86-
### Melt Example 1
86+
### Melt example 1
8787

8888
We melt the dataframe by specifying the identifier columns via `id_vars`. The “leftover” non-identifier columns (english, math, physics) will be melted or stacked onto each other into one column.
8989

@@ -101,7 +101,7 @@ pd.melt(frame=df_wide,
101101

102102
![Wide to long: new indicator column “cLaSs” + values melted/stacked “gRaDe” column](./pic3.png)
103103

104-
### Melt Example 2
104+
### Melt example 2
105105

106106
You can use `value_vars` to specify which columns you want to melt or stack into column (here, we exclude physics column, so `value_vars=["english", "math"]`). We also drop the school column from `id_vars`.
107107

@@ -118,7 +118,7 @@ pd.melt(frame=df_wide,
118118

119119
![Wide to long: original columns school and physics have been dropped](./pic4.png)
120120

121-
### Melt Example 3
121+
### Melt example 3
122122

123123
Finally, let’s see what happens if we specify only the student column as the identifier column (`id_vars="student"`) but do not specify which columns you want to stack via `value_vars`. As a result, all non-identifier columns (school, english, math, physics) will be stacked into one column.
124124

@@ -140,6 +140,6 @@ This table looks wrong because the `school` column in `df_wide` doesn't belong
140140

141141
## Support my work
142142

143-
I hope now you have a better understanding of how `pd.melt` reshapes dataframes. If you find this post useful, check out my other articles and visit my [Medium page](https://medium.com/@ausius).
143+
I hope now you have a better understanding of how `pd.melt` reshapes dataframes. If you find this post useful, check out my other articles and folow me on [Medium ](https://medium.com/@ausius).
144144

145145
If you've enjoyed my article, [support my work and become a patron here](https://donorbox.org/support-my-teaching)!

_posts/2020-05-14-reshaping-data-in-python-pandas/reshaping-data-in-python-pandas.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -969,23 +969,23 @@ <h3 class="d-toc-header">Table of Contents</h3>
969969
<li><a href="#consider-being-a-patron-and-supporting-my-work">Consider being a patron and supporting my work?</a></li>
970970
<li><a href="#wide-data">Wide data</a></li>
971971
<li><a href="#wide-to-long-with-melt">Wide to long with <code>melt</code></a><ul>
972-
<li><a href="#melt-example-1">Melt Example 1</a></li>
973-
<li><a href="#melt-example-2">Melt Example 2</a></li>
974-
<li><a href="#melt-example-3">Melt Example 3</a></li>
972+
<li><a href="#melt-example-1">Melt example 1</a></li>
973+
<li><a href="#melt-example-2">Melt example 2</a></li>
974+
<li><a href="#melt-example-3">Melt example 3</a></li>
975975
</ul></li>
976976
<li><a href="#support-my-work">Support my work</a></li>
977977
</ul>
978978
</nav>
979979
<hr class="d-toc-separator"/>
980980
<p>Get source code for this RMarkdown script <a href="https://raw.githubusercontent.com/hauselin/rtutorialsite/master/_posts/2020-05-17-reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable/reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable.Rmd">here</a>.</p>
981-
<p>This Python tutorial is also available on <a href="https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02">Medium, Towards Data Science</a>. Click here if you’re looking for the R version of melt (also the <code>melt</code> function in R).</p>
981+
<p>This Python tutorial is on <a href="https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02">Medium, Towards Data Science</a>. Click here if you’re looking for the tutorial for the R version of melt (also the <code>melt</code> function in R).</p>
982982
<h2 id="consider-being-a-patron-and-supporting-my-work">Consider being a patron and supporting my work?</h2>
983983
<p><a href="https://donorbox.org/support-my-teaching">Donate and become a patron</a>: If you find value in what I do and have learned something from my site, please consider becoming a patron. It takes me many hours to research, learn, and put together tutorials. Your support really matters.</p>
984984
<p>How does the pandas <code>melt()</code> method reshape dataframes? How do you reshape a dataframe from wide to long form? This tutorial will walk you through reshaping dataframes using <code>pd.melt()</code> or the <code>melt</code> method associated with pandas dataframes.</p>
985985
<figure>
986986
<img src="main_wide2long.png" alt="Summary of how pd.melt() works" /><figcaption>Summary of how pd.melt() works</figcaption>
987987
</figure>
988-
<p>Also, you might want to check out the official pandas documentation and my <a href="https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02">numpy reshape tutorial</a>.</p>
988+
<p>Also, you might want to check out the official pandas documentation and my <a href="https://towardsdatascience.com/reshaping-numpy-arrays-in-python-a-step-by-step-pictorial-tutorial-aed5f471cf0b?source=friends_link&amp;sk=3dc229066e89cb5bcd4bb86b301f0a5c">numpy reshape tutorial</a>.</p>
989989
<p>Let’s load the <code>reticulate</code> library in R so we can run Python in RStudio. I’ll then load my conda python environment. I highly recommend you try the code in Python while you read this article. Try running this tutorial on my shared <a href="https://beta.deepnote.com/project/d1350ad6-bcb4-4c3d-857b-c29d01b8a803">DeepNote notebook</a> (you can only run but not edit this notebook).</p>
990990
<div class="layout-chunk" data-layout="l-body">
991991
<pre class="r"><code>
@@ -1031,7 +1031,7 @@ <h2 id="wide-data">Wide data</h2>
10311031
</div>
10321032
<h2 id="wide-to-long-with-melt">Wide to long with <code>melt</code></h2>
10331033
<p>Common terms for this transformation are melt, unpivot, gather, stack. See <code>pd.melt()</code> documentation <a href="https://pandas.pydata.org/docs/reference/api/pandas.melt.html">here</a>.</p>
1034-
<h3 id="melt-example-1">Melt Example 1</h3>
1034+
<h3 id="melt-example-1">Melt example 1</h3>
10351035
<p>We melt the dataframe by specifying the identifier columns via <code>id_vars</code>. The “leftover” non-identifier columns (english, math, physics) will be melted or stacked onto each other into one column.</p>
10361036
<p>A new indicator column will be created (contains values english, math, physics) and we can rename this new column (cLaSs) via <code>var_name</code>. We can also rename the column in which all the actual grades are contained (gRaDe) via <code>value_name</code>.</p>
10371037
<div class="layout-chunk" data-layout="l-body">
@@ -1061,7 +1061,7 @@ <h3 id="melt-example-1">Melt Example 1</h3>
10611061
<figure>
10621062
<img src="pic3.png" alt="Wide to long: new indicator column “cLaSs” + values melted/stacked “gRaDe” column" /><figcaption>Wide to long: new indicator column “cLaSs” + values melted/stacked “gRaDe” column</figcaption>
10631063
</figure>
1064-
<h3 id="melt-example-2">Melt Example 2</h3>
1064+
<h3 id="melt-example-2">Melt example 2</h3>
10651065
<p>You can use <code>value_vars</code> to specify which columns you want to melt or stack into column (here, we exclude physics column, so <code>value_vars=[&quot;english&quot;, &quot;math&quot;]</code>). We also drop the school column from <code>id_vars</code>.</p>
10661066
<div class="layout-chunk" data-layout="l-body">
10671067
<pre class="python"><code>
@@ -1087,7 +1087,7 @@ <h3 id="melt-example-2">Melt Example 2</h3>
10871087
<figure>
10881088
<img src="pic4.png" alt="Wide to long: original columns school and physics have been dropped" /><figcaption>Wide to long: original columns school and physics have been dropped</figcaption>
10891089
</figure>
1090-
<h3 id="melt-example-3">Melt Example 3</h3>
1090+
<h3 id="melt-example-3">Melt example 3</h3>
10911091
<p>Finally, let’s see what happens if we specify only the student column as the identifier column (<code>id_vars=&quot;student&quot;</code>) but do not specify which columns you want to stack via <code>value_vars</code>. As a result, all non-identifier columns (school, english, math, physics) will be stacked into one column.</p>
10921092
<p>The resulting long dataframe looks wrong because now the cLaSs and gRaDe columns contain values that shouldn’t be there. The point here is to show you how <code>pd.melt</code> works.</p>
10931093
<div class="layout-chunk" data-layout="l-body">
@@ -1123,7 +1123,7 @@ <h3 id="melt-example-3">Melt Example 3</h3>
11231123
<img src="pic5.png" alt="Wide to long: school column isn’t an identifier column" /><figcaption>Wide to long: school column isn’t an identifier column</figcaption>
11241124
</figure>
11251125
<h2 id="support-my-work">Support my work</h2>
1126-
<p>I hope now you have a better understanding of how <code>pd.melt</code> reshapes dataframes. If you find this post useful, check out my other articles and visit my <a href="https://medium.com/@ausius">Medium page</a>.</p>
1126+
<p>I hope now you have a better understanding of how <code>pd.melt</code> reshapes dataframes. If you find this post useful, check out my other articles and folow me on <a href="https://medium.com/@ausius">Medium</a>.</p>
11271127
<p>If you’ve enjoyed my article, <a href="https://donorbox.org/support-my-teaching">support my work and become a patron here</a>!</p>
11281128
<!--radix_placeholder_article_footer-->
11291129
<!--/radix_placeholder_article_footer-->

_posts/2020-05-17-reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable/reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable.Rmd

+7-5
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ editor_options:
2525
knitr::opts_chunk$set(echo = TRUE, cache = FALSE, comment = NA, message = FALSE, warning = FALSE)
2626
```
2727

28-
Get source code for this RMarkdown script [here](https://raw.githubusercontent.com/hauselin/rtutorialsite/master/_posts/2020-05-14-reshaping-data-in-python-pandas/reshaping-data-in-python-pandas.Rmd).
28+
Get source code for this RMarkdown script [here](https://raw.githubusercontent.com/hauselin/rtutorialsite/master/_posts/2020-05-17-reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable/reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable.Rmd).
2929

30-
This Python tutorial is also available on [Medium, Towards Data Science](https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02). Click here if you're looking for the R version of melt (also the `dcast` function in R).
30+
This Python tutorial is also on [Medium, Towards Data Science](https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02). Click here if you're looking for the tutorail for the R version of `pivot_table` (also the `dcast` function in R).
31+
32+
The opposite of `pivot_table` is `melt`, and you can find the tutorial for `melt` (wide to long) [here](https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02?source=friends_link&sk=5200888fd2030a2ede726c00dec8b610).
3133

3234
## Consider being a patron and supporting my work?
3335

3436
[Donate and become a patron](https://donorbox.org/support-my-teaching): If you find value in what I do and have learned something from my site, please consider becoming a patron. It takes me many hours to research, learn, and put together tutorials. Your support really matters.
3537

36-
How does the pandas `pivot_table()` method reshape dataframes? How do you reshape a dataframe from wide to long form? This tutorial will walk you through reshaping dataframes using `pd.pivot_table()` or the `pivot_table` method associated with pandas dataframes.
38+
How does the pandas `pivot_table()` method reshape dataframes? How do you reshape a dataframe from long to wide form? This tutorial will walk you through reshaping dataframes using `pd.pivot_table()` or the `pivot_table` method associated with pandas dataframes.
3739

3840
![Summary of how pd.pivot_table() works](pic1.png)
3941

40-
Also, you might want to check out the official pandas documentation and my [numpy reshape tutorial](https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02).
42+
Also, you might want to check out the official pandas documentation and my [numpy reshape tutorial](https://towardsdatascience.com/reshaping-numpy-arrays-in-python-a-step-by-step-pictorial-tutorial-aed5f471cf0b?source=friends_link&sk=3dc229066e89cb5bcd4bb86b301f0a5c).
4143

4244
Let's load the `reticulate` library in R so we can run Python in RStudio. I'll then load my conda python environment. I highly recommend you try the code in Python while you read this article. Try running this tutorial on my shared [DeepNote notebook](https://beta.deepnote.com/project/b494e5b7-9e5c-4e06-8a4a-43130d27aa3f) (you can only run but not edit this notebook).
4345

@@ -145,6 +147,6 @@ https://stackoverflow.com/questions/22798934/pandas-long-to-wide-reshape-by-two-
145147

146148
## Support my work
147149

148-
I hope now you have a better understanding of how `pd.pivot_table` reshapes dataframes. If you find this post useful, check out my other articles and visit my [Medium page](https://medium.com/@ausius).
150+
I hope now you have a better understanding of how `pd.pivot_table` reshapes dataframes. If you find this post useful, check out my other articles and folow me on [Medium ](https://medium.com/@ausius).
149151

150152
If you've enjoyed my article, [support my work and become a patron here](https://donorbox.org/support-my-teaching)!

_posts/2020-05-17-reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable/reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -976,15 +976,16 @@ <h3 class="d-toc-header">Table of Contents</h3>
976976
</ul>
977977
</nav>
978978
<hr class="d-toc-separator"/>
979-
<p>Get source code for this RMarkdown script <a href="https://raw.githubusercontent.com/hauselin/rtutorialsite/master/_posts/2020-05-14-reshaping-data-in-python-pandas/reshaping-data-in-python-pandas.Rmd">here</a>.</p>
980-
<p>This Python tutorial is also available on <a href="https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02">Medium, Towards Data Science</a>. Click here if you’re looking for the R version of melt (also the <code>dcast</code> function in R).</p>
979+
<p>Get source code for this RMarkdown script <a href="https://raw.githubusercontent.com/hauselin/rtutorialsite/master/_posts/2020-05-17-reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable/reshape-python-pandas-dataframe-from-long-to-wide-with-pivottable.Rmd">here</a>.</p>
980+
<p>This Python tutorial is also on <a href="https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02">Medium, Towards Data Science</a>. Click here if you’re looking for the tutorail for the R version of <code>pivot_table</code> (also the <code>dcast</code> function in R).</p>
981+
<p>The opposite of <code>pivot_table</code> is <code>melt</code>, and you can find the tutorial for <code>melt</code> (wide to long) <a href="https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02?source=friends_link&amp;sk=5200888fd2030a2ede726c00dec8b610">here</a>.</p>
981982
<h2 id="consider-being-a-patron-and-supporting-my-work">Consider being a patron and supporting my work?</h2>
982983
<p><a href="https://donorbox.org/support-my-teaching">Donate and become a patron</a>: If you find value in what I do and have learned something from my site, please consider becoming a patron. It takes me many hours to research, learn, and put together tutorials. Your support really matters.</p>
983-
<p>How does the pandas <code>pivot_table()</code> method reshape dataframes? How do you reshape a dataframe from wide to long form? This tutorial will walk you through reshaping dataframes using <code>pd.pivot_table()</code> or the <code>pivot_table</code> method associated with pandas dataframes.</p>
984+
<p>How does the pandas <code>pivot_table()</code> method reshape dataframes? How do you reshape a dataframe from long to wide form? This tutorial will walk you through reshaping dataframes using <code>pd.pivot_table()</code> or the <code>pivot_table</code> method associated with pandas dataframes.</p>
984985
<figure>
985986
<img src="pic1.png" alt="Summary of how pd.pivot_table() works" /><figcaption>Summary of how pd.pivot_table() works</figcaption>
986987
</figure>
987-
<p>Also, you might want to check out the official pandas documentation and my <a href="https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02">numpy reshape tutorial</a>.</p>
988+
<p>Also, you might want to check out the official pandas documentation and my <a href="https://towardsdatascience.com/reshaping-numpy-arrays-in-python-a-step-by-step-pictorial-tutorial-aed5f471cf0b?source=friends_link&amp;sk=3dc229066e89cb5bcd4bb86b301f0a5c">numpy reshape tutorial</a>.</p>
988989
<p>Let’s load the <code>reticulate</code> library in R so we can run Python in RStudio. I’ll then load my conda python environment. I highly recommend you try the code in Python while you read this article. Try running this tutorial on my shared <a href="https://beta.deepnote.com/project/b494e5b7-9e5c-4e06-8a4a-43130d27aa3f">DeepNote notebook</a> (you can only run but not edit this notebook).</p>
989990
<div class="layout-chunk" data-layout="l-body">
990991
<pre class="r"><code>
@@ -1154,7 +1155,7 @@ <h2 id="resources">Resources</h2>
11541155
<p><a href="https://chrisalbon.com/python/data_wrangling/pandas_pivot_tables/" class="uri">https://chrisalbon.com/python/data_wrangling/pandas_pivot_tables/</a></p>
11551156
<p><a href="https://stackoverflow.com/questions/22798934/pandas-long-to-wide-reshape-by-two-variables" class="uri">https://stackoverflow.com/questions/22798934/pandas-long-to-wide-reshape-by-two-variables</a></p>
11561157
<h2 id="support-my-work">Support my work</h2>
1157-
<p>I hope now you have a better understanding of how <code>pd.pivot_table</code> reshapes dataframes. If you find this post useful, check out my other articles and visit my <a href="https://medium.com/@ausius">Medium page</a>.</p>
1158+
<p>I hope now you have a better understanding of how <code>pd.pivot_table</code> reshapes dataframes. If you find this post useful, check out my other articles and folow me on <a href="https://medium.com/@ausius">Medium</a>.</p>
11581159
<p>If you’ve enjoyed my article, <a href="https://donorbox.org/support-my-teaching">support my work and become a patron here</a>!</p>
11591160
<!--radix_placeholder_article_footer-->
11601161
<!--/radix_placeholder_article_footer-->

0 commit comments

Comments
 (0)