|
348 | 348 | } |
349 | 349 | ], |
350 | 350 | "source": [ |
351 | | - "berri_bikes.loc[:,'weekday'] = berri_bikes.index.weekday\n", |
| 351 | + "berri_bikes['weekday'] = berri_bikes.index.weekday\n", |
352 | 352 | "berri_bikes[:5]" |
353 | 353 | ] |
354 | 354 | }, |
|
367 | 367 | "\n", |
368 | 368 | "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", |
369 | 369 | "\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\"." |
371 | 371 | ] |
372 | 372 | }, |
373 | 373 | { |
|
454 | 454 | } |
455 | 455 | ], |
456 | 456 | "source": [ |
457 | | - "weekday_counts = berri_bikes.groupby('weekday').aggregate(sum)\n", |
| 457 | + "weekday_counts = berri_bikes.groupby('weekday').sum()\n", |
458 | 458 | "weekday_counts" |
459 | 459 | ] |
460 | 460 | }, |
|
634 | 634 | " index_col='Date')\n", |
635 | 635 | "# Add the weekday column\n", |
636 | 636 | "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", |
638 | 638 | "\n", |
639 | 639 | "# 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", |
641 | 641 | "weekday_counts.index = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n", |
642 | 642 | "weekday_counts.plot(kind='bar')" |
643 | 643 | ] |
|
0 commit comments