Skip to content

Commit 5429880

Browse files
Add a warning about double indexing whenm modifying a DF.
1 parent 776c5d7 commit 5429880

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

climate_timeseries/climate_timeseries-Part2.ipynb

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,70 @@
352352
"local_sea_level_stations.loc[american_stations, [\"ID\", \"Station Name\"]]"
353353
]
354354
},
355+
{
356+
"cell_type": "markdown",
357+
"metadata": {},
358+
"source": [
359+
"## Warning: modifying a dataframe with multiple indexing"
360+
]
361+
},
362+
{
363+
"cell_type": "code",
364+
"execution_count": null,
365+
"metadata": {
366+
"collapsed": false
367+
},
368+
"outputs": [],
369+
"source": [
370+
"giss_temp"
371+
]
372+
},
373+
{
374+
"cell_type": "code",
375+
"execution_count": null,
376+
"metadata": {
377+
"collapsed": false
378+
},
379+
"outputs": [],
380+
"source": [
381+
"giss_temp['Jan']"
382+
]
383+
},
384+
{
385+
"cell_type": "code",
386+
"execution_count": null,
387+
"metadata": {
388+
"collapsed": false
389+
},
390+
"outputs": [],
391+
"source": [
392+
"# This works right now, but this is dangerous:\n",
393+
"giss_temp['Jan'][1880] = -33.9"
394+
]
395+
},
396+
{
397+
"cell_type": "code",
398+
"execution_count": null,
399+
"metadata": {
400+
"collapsed": false
401+
},
402+
"outputs": [],
403+
"source": [
404+
"giss_temp"
405+
]
406+
},
407+
{
408+
"cell_type": "code",
409+
"execution_count": null,
410+
"metadata": {
411+
"collapsed": true
412+
},
413+
"outputs": [],
414+
"source": [
415+
"# This is the safe way to do it:\n",
416+
"giss_temp.loc[1880, 'Jan'] = -33.9"
417+
]
418+
},
355419
{
356420
"cell_type": "markdown",
357421
"metadata": {},
@@ -2082,22 +2146,23 @@
20822146
}
20832147
],
20842148
"metadata": {
2149+
"anaconda-cloud": {},
20852150
"kernelspec": {
2086-
"display_name": "Python 2",
2151+
"display_name": "Python [Root]",
20872152
"language": "python",
2088-
"name": "python2"
2153+
"name": "Python [Root]"
20892154
},
20902155
"language_info": {
20912156
"codemirror_mode": {
20922157
"name": "ipython",
2093-
"version": 2
2158+
"version": 3
20942159
},
20952160
"file_extension": ".py",
20962161
"mimetype": "text/x-python",
20972162
"name": "python",
20982163
"nbconvert_exporter": "python",
2099-
"pygments_lexer": "ipython2",
2100-
"version": "2.7.10"
2164+
"pygments_lexer": "ipython3",
2165+
"version": "3.5.2"
21012166
}
21022167
},
21032168
"nbformat": 4,

0 commit comments

Comments
 (0)