Last active
September 14, 2020 11:28
-
-
Save apahl/5ea03e47e180f05e27fca49504ec082d 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": 1, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-09-14T11:16:34.338195Z", | |
"start_time": "2020-09-14T11:16:34.162165Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-09-14T11:17:44.386708Z", | |
"start_time": "2020-09-14T11:17:44.383592Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"df = pd.DataFrame(data={\"Values\": range(1, 100000)})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-09-14T11:18:50.097534Z", | |
"start_time": "2020-09-14T11:18:44.932428Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 5.15 s, sys: 3.78 ms, total: 5.16 s\n", | |
"Wall time: 5.15 s\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"4999950000" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%time\n", | |
"summed = 0\n", | |
"for _, rec in df.iterrows():\n", | |
" summed += rec[\"Values\"]\n", | |
"\n", | |
"summed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-09-14T11:25:52.014131Z", | |
"start_time": "2020-09-14T11:25:51.973010Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 37.4 ms, sys: 0 ns, total: 37.4 ms\n", | |
"Wall time: 36.8 ms\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"4999950000" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%time\n", | |
"summed = 0\n", | |
"for rec in df.itertuples(index=False):\n", | |
" summed += rec.Values\n", | |
"\n", | |
"summed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2020-09-14T11:25:49.803594Z", | |
"start_time": "2020-09-14T11:25:42.459221Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU times: user 7.34 s, sys: 0 ns, total: 7.34 s\n", | |
"Wall time: 7.34 s\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"4999950000" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%time\n", | |
"summed = 0\n", | |
"for idx in range(len(df)):\n", | |
" rec = df.iloc[idx]\n", | |
" summed += rec[\"Values\"]\n", | |
"\n", | |
"summed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"hide_input": false, | |
"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.8.3" | |
}, | |
"toc": { | |
"base_numbering": 1, | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": true, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment