Skip to content

Commit 69d3389

Browse files
authored
Merge pull request #79 from caringrad/patch-1
simplified code - removed .loc and aggregate()
2 parents 3b1c3d6 + 50b30d3 commit 69d3389

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cookbook/Chapter 4 - Find out on which weekday people bike the most with groupby and aggregate.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@
348348
}
349349
],
350350
"source": [
351-
"berri_bikes.loc[:,'weekday'] = berri_bikes.index.weekday\n",
351+
"berri_bikes['weekday'] = berri_bikes.index.weekday\n",
352352
"berri_bikes[:5]"
353353
]
354354
},
@@ -367,7 +367,7 @@
367367
"\n",
368368
"Dataframes have a `.groupby()` method that is similar to SQL groupby, if you're familiar with that. I'm not going to explain more about it right now -- if you want to to know more, [the documentation](http://pandas.pydata.org/pandas-docs/stable/groupby.html) is really good.\n",
369369
"\n",
370-
"In this case, `berri_bikes.groupby('weekday').aggregate(sum)` means \"Group the rows by weekday and then add up all the values with the same weekday\"."
370+
"In this case, `berri_bikes.groupby('weekday').sum()` means \"Group the rows by weekday and then add up all the values with the same weekday\"."
371371
]
372372
},
373373
{
@@ -454,7 +454,7 @@
454454
}
455455
],
456456
"source": [
457-
"weekday_counts = berri_bikes.groupby('weekday').aggregate(sum)\n",
457+
"weekday_counts = berri_bikes.groupby('weekday').sum()\n",
458458
"weekday_counts"
459459
]
460460
},
@@ -634,10 +634,10 @@
634634
" index_col='Date')\n",
635635
"# Add the weekday column\n",
636636
"berri_bikes = bikes[['Berri 1']].copy()\n",
637-
"berri_bikes.loc[:,'weekday'] = berri_bikes.index.weekday\n",
637+
"berri_bikes['weekday'] = berri_bikes.index.weekday\n",
638638
"\n",
639639
"# Add up the number of cyclists by weekday, and plot!\n",
640-
"weekday_counts = berri_bikes.groupby('weekday').aggregate(sum)\n",
640+
"weekday_counts = berri_bikes.groupby('weekday').sum()\n",
641641
"weekday_counts.index = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n",
642642
"weekday_counts.plot(kind='bar')"
643643
]

0 commit comments

Comments
 (0)