From 2bdaa812a43d810db9bc6587badb4a58b58299a2 Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Tue, 31 Mar 2015 16:20:41 +0200 Subject: [PATCH] Fix SettingWithCopyWarning --- ... the most with groupby and aggregate.ipynb | 127 +- ...s and scraping Canadian weather data.ipynb | 4270 ++++++++--------- ... 9 - Loading data from SQL databases.ipynb | 183 +- 3 files changed, 2222 insertions(+), 2358 deletions(-) diff --git a/cookbook/Chapter 4 - Find out on which weekday people bike the most with groupby and aggregate.ipynb b/cookbook/Chapter 4 - Find out on which weekday people bike the most with groupby and aggregate.ipynb index f59e35b1f..6792fe714 100644 --- a/cookbook/Chapter 4 - Find out on which weekday people bike the most with groupby and aggregate.ipynb +++ b/cookbook/Chapter 4 - Find out on which weekday people bike the most with groupby and aggregate.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 21, + "execution_count": 1, "metadata": { "collapsed": false }, @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 2, "metadata": { "collapsed": false }, @@ -54,10 +54,10 @@ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 22, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" }, @@ -1160,7 +1160,7 @@ "jhBCCCGEEELiCE3iCCGEEEIIISSO0CSOEEIIIYQQQuLI/w9RfarSpacS1QAAAABJRU5ErkJggg==\n" ], "text/plain": [ - "" + "" ] }, "metadata": {}, @@ -1183,18 +1183,18 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "berri_bikes = bikes[['Berri 1']]" + "berri_bikes = bikes[['Berri 1']].copy()" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -1249,7 +1249,7 @@ "2012-01-05 197" ] }, - "execution_count": 24, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -1267,7 +1267,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -1280,7 +1280,7 @@ "Length: 310, Freq: None, Timezone: None" ] }, - "execution_count": 25, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -1300,7 +1300,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 6, "metadata": { "collapsed": false }, @@ -1329,7 +1329,7 @@ " 2, 3, 4, 5], dtype=int32)" ] }, - "execution_count": 26, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -1347,7 +1347,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 7, "metadata": { "collapsed": false }, @@ -1371,7 +1371,7 @@ " 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0], dtype=int32)" ] }, - "execution_count": 27, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -1391,7 +1391,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 8, "metadata": { "collapsed": false }, @@ -1453,7 +1453,7 @@ "2012-01-05 197 3" ] }, - "execution_count": 28, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -1483,7 +1483,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 9, "metadata": { "collapsed": false }, @@ -1548,7 +1548,7 @@ "6 99310" ] }, - "execution_count": 29, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -1567,7 +1567,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 10, "metadata": { "collapsed": false }, @@ -1627,7 +1627,7 @@ "Sunday 99310" ] }, - "execution_count": 30, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -1639,7 +1639,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 11, "metadata": { "collapsed": false }, @@ -1647,10 +1647,10 @@ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 31, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" }, @@ -1972,7 +1972,7 @@ "AAAAAElFTkSuQmCC\n" ], "text/plain": [ - "" + "" ] }, "metadata": {}, @@ -2008,30 +2008,18 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py:245: SettingWithCopyWarning: \n", - "A value is trying to be set on a copy of a slice from a DataFrame.\n", - "Try using .loc[row_indexer,col_indexer] = value instead\n", - "\n", - "See the the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n", - " self.obj[key] = np.nan\n" - ] - }, { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 20, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" }, @@ -2353,7 +2341,7 @@ "AAAAAElFTkSuQmCC\n" ], "text/plain": [ - "" + "" ] }, "metadata": {}, @@ -2366,7 +2354,7 @@ " parse_dates=['Date'], dayfirst=True, \n", " index_col='Date')\n", "# Add the weekday column\n", - "berri_bikes = bikes[['Berri 1']]\n", + "berri_bikes = bikes[['Berri 1']].copy()\n", "berri_bikes.loc[:,'weekday'] = berri_bikes.index.weekday\n", "\n", "# Add up the number of cyclists by weekday, and plot!\n", @@ -2374,59 +2362,11 @@ "weekday_counts.index = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n", "weekday_counts.plot(kind='bar')" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "