Skip to content

Commit

Permalink
Fix SettingWithCopyWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
c-martinez committed Mar 31, 2015
1 parent 96d2e53 commit 2bdaa81
Show file tree
Hide file tree
Showing 3 changed files with 2,222 additions and 2,358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 1,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -46,18 +46,18 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.axes._subplots.AxesSubplot at 0x7fece0de6050>"
"<matplotlib.axes._subplots.AxesSubplot at 0x7f082e34dad0>"
]
},
"execution_count": 22,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -1160,7 +1160,7 @@
"jhBCCCGEEELiCE3iCCGEEEIIISSO0CSOEEIIIYQQQuLI/w9RfarSpacS1QAAAABJRU5ErkJggg==\n"
],
"text/plain": [
"<matplotlib.figure.Figure at 0x7fece0d66dd0>"
"<matplotlib.figure.Figure at 0x7f084c534910>"
]
},
"metadata": {},
Expand All @@ -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
},
Expand Down Expand Up @@ -1249,7 +1249,7 @@
"2012-01-05 197"
]
},
"execution_count": 24,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1267,7 +1267,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 5,
"metadata": {
"collapsed": false
},
Expand All @@ -1280,7 +1280,7 @@
"Length: 310, Freq: None, Timezone: None"
]
},
"execution_count": 25,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1300,7 +1300,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 6,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1329,7 +1329,7 @@
" 2, 3, 4, 5], dtype=int32)"
]
},
"execution_count": 26,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1347,7 +1347,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 7,
"metadata": {
"collapsed": false
},
Expand All @@ -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"
}
Expand All @@ -1391,7 +1391,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1453,7 +1453,7 @@
"2012-01-05 197 3"
]
},
"execution_count": 28,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -1483,7 +1483,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 9,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1548,7 +1548,7 @@
"6 99310"
]
},
"execution_count": 29,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1567,7 +1567,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 10,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1627,7 +1627,7 @@
"Sunday 99310"
]
},
"execution_count": 30,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1639,18 +1639,18 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.axes._subplots.AxesSubplot at 0x7fece0ad2fd0>"
"<matplotlib.axes._subplots.AxesSubplot at 0x7f082df35490>"
]
},
"execution_count": 31,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -1972,7 +1972,7 @@
"AAAAAElFTkSuQmCC\n"
],
"text/plain": [
"<matplotlib.figure.Figure at 0x7fece0d02590>"
"<matplotlib.figure.Figure at 0x7f084c53eb50>"
]
},
"metadata": {},
Expand Down Expand Up @@ -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": [
"<matplotlib.axes._subplots.AxesSubplot at 0x7fece0d6fc50>"
"<matplotlib.axes._subplots.AxesSubplot at 0x7f082dd7f790>"
]
},
"execution_count": 20,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -2353,7 +2341,7 @@
"AAAAAElFTkSuQmCC\n"
],
"text/plain": [
"<matplotlib.figure.Figure at 0x7fece0d3a9d0>"
"<matplotlib.figure.Figure at 0x7f082dd74150>"
]
},
"metadata": {},
Expand All @@ -2366,67 +2354,19 @@
" 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",
"weekday_counts = berri_bikes.groupby('weekday').aggregate(sum)\n",
"weekday_counts.index = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n",
"weekday_counts.plot(kind='bar')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<style>\n",
" @font-face {\n",
" font-family: \"Computer Modern\";\n",
" src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n",
" }\n",
" div.cell{\n",
" width:800px;\n",
" margin-left:16% !important;\n",
" margin-right:auto;\n",
" }\n",
" h1 {\n",
" font-family: Helvetica, serif;\n",
" }\n",
" h4{\n",
" margin-top:12px;\n",
" margin-bottom: 3px;\n",
" }\n",
" div.text_cell_render{\n",
" font-family: Computer Modern, \"Helvetica Neue\", Arial, Helvetica, Geneva, sans-serif;\n",
" line-height: 145%;\n",
" font-size: 130%;\n",
" width:800px;\n",
" margin-left:auto;\n",
" margin-right:auto;\n",
" }\n",
" .CodeMirror{\n",
" font-family: \"Source Code Pro\", source-code-pro,Consolas, monospace;\n",
" }\n",
" .text_cell_render h5 {\n",
" font-weight: 300;\n",
" font-size: 22pt;\n",
" color: #4057A1;\n",
" font-style: italic;\n",
" margin-bottom: .5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" }\n",
" \n",
" .warning{\n",
" color: rgb( 240, 20, 20 )\n",
" } "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
Expand All @@ -2439,9 +2379,10 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
"version": "2.7.8"
},
"signature": "sha256:fc65c5245eb0b7b16ea28251f067cbbe64e7da1b9340f0f03fc786c53807a96c"
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Loading

0 comments on commit 2bdaa81

Please sign in to comment.