Created
August 1, 2016 02:01
-
-
Save davclark/228bc2a73afbd6a13b12bed0682a736a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"class SelfConscious:\n", | |
" called = 0\n", | |
" \n", | |
" def __init__(self, label):\n", | |
" self.label = label\n", | |
" \n", | |
" def increment(self):\n", | |
" self.called += 1\n", | |
" print('object {} called {} times'.format(self.label, self.called))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"object 0 called 1 times\n", | |
"object 0 called 2 times\n" | |
] | |
} | |
], | |
"source": [ | |
"sc = SelfConscious(0)\n", | |
"sc.increment()\n", | |
"sc.increment()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>sc</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td><__main__.SelfConscious object at 0x10aa6b898></td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td><__main__.SelfConscious object at 0x10aa6b8d0></td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td><__main__.SelfConscious object at 0x10aa6b940></td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td><__main__.SelfConscious object at 0x10aa6ba20></td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" sc\n", | |
"0 <__main__.SelfConscious object at 0x10aa6b898>\n", | |
"1 <__main__.SelfConscious object at 0x10aa6b8d0>\n", | |
"2 <__main__.SelfConscious object at 0x10aa6b940>\n", | |
"3 <__main__.SelfConscious object at 0x10aa6ba20>" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"scs = pd.DataFrame({'sc': [SelfConscious(label) for label in range(4)]})\n", | |
"scs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"object 0 called 1 times\n", | |
"object 1 called 1 times\n", | |
"object 2 called 1 times\n", | |
"object 3 called 1 times\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"0 None\n", | |
"1 None\n", | |
"2 None\n", | |
"3 None\n", | |
"Name: sc, dtype: object" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"scs.sc.apply(lambda x: x.increment())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment