Skip to content

Commit f290958

Browse files
authored
Update 12-long-and-wide.md
1 parent 85334c5 commit f290958

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

_episodes/12-long-and-wide.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ We will create a new Dataframe with a single column of 'Id'.
4242

4343
~~~
4444
# create an 'Id' column
45-
df_papers1 = pd.DataFrame(pd.Series(range(1,1287)),index=None,columns=['Id'])
45+
df_papers1 = pd.DataFrame(pd.Series(range(1,1287)), index=None, columns=['Id'])
4646
~~~
4747
{: .language-python}
4848

49-
Using the range function I can create values of Id starting with 1 and going up to 1286 (remember the second parameter to range is one past the last value used.) I have explicitly coded this value because I knew how many rows were in the dataset. If I didn't, I could have used
49+
Using the range function, we can create values of `Id` starting with 1 and going up to 1286 (remember the second parameter to range is one past the last value used.) We have explicitly coded this value because we knew how many rows were in the dataset. If we didn't, we could have used
5050

5151
~~~
5252
len(df_SN7577.index) +1
@@ -60,7 +60,7 @@ len(df_SN7577.index) +1
6060

6161
We will create a 2nd Dataframe, based on SN7577 but containing only the columns starting with the word 'daily'.
6262

63-
There are several ways of doing this, we'll cover the way that we have covered all of the prerequistes for. We will use the `filter` method of `pandas` with its `like` parameter.
63+
There are several ways of doing this, we'll cover the way that we have covered all of the prerequisites for. We will use the `filter` method of `pandas` with its `like` parameter.
6464

6565
~~~
6666
df_papers2 = df_SN7577.filter(like= 'daily')
@@ -114,8 +114,8 @@ daily_list = df_papers.columns[1:8]
114114

115115
df_daily_papers_long = pd.melt(df_papers, id_vars = ['Id'], value_vars = daily_list)
116116

117-
# by default the new columns created will be called 'variable' which is the name of the 'daily'
118-
# and 'value' which is the value of that 'daily' for that 'Id'. So we will rename the columns
117+
# by default, the new columns created will be called 'variable' which is the name of the 'daily'
118+
# and 'value' which is the value of that 'daily' for that 'Id'. So, we will rename the columns
119119

120120
df_daily_papers_long.columns = ['Id','Daily_paper','Value']
121121
df_daily_papers_long
@@ -166,7 +166,7 @@ df_daily_papers_wide.reset_index(level=0, inplace=True)
166166
>
167167
> There is a file called Newspapers.csv which lists all of the newspapers Titles along with the corresponding 'daily' value
168168
>
169-
> Hint : Newspapers.csv cotains both daily and Sunday newspapers you can filter out the Sunday papers with the following code:
169+
> Hint: Newspapers.csv contains both daily and Sunday newspapers you can filter out the Sunday papers with the following code:
170170
>
171171
>
172172
> ~~~
@@ -205,7 +205,7 @@ df_daily_papers_wide.reset_index(level=0, inplace=True)
205205
> > #use melt to create df_daily_papers_long
206206
> > df_daily_papers_long = pd.melt(df_papers, id_vars = ['Id'], value_vars = daily_list )
207207
> > #Change the column names
208-
> > df_daily_papers_long.columns = ['Id','Daily_paper','Value']
208+
> > df_daily_papers_long.columns = ['Id', 'Daily_paper', 'Value']
209209
> > ```
210210
> >
211211
> > 5. `merge` the two Dataframes with a left join, because we want all of the Newspaper Titles to be included.

0 commit comments

Comments
 (0)