Skip to content

Instantly share code, notes, and snippets.

@stared
Last active August 29, 2015 14:00
Show Gist options
  • Save stared/11283514 to your computer and use it in GitHub Desktop.
Save stared/11283514 to your computer and use it in GitHub Desktop.
Pandas and Numpy - performance for Series vs 1d array multiplication
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:b8577d56627577137290c84381ac40e5df7df64f16169e46dc25c38c8a0bc5eb"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import pandas as pd\n",
"import numpy as np"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"rands1 = np.random.randn(10**7)\n",
"rands2 = np.random.randn(10**7)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%timeit\n",
"\n",
"rands3np = rands1 * rands2"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"10 loops, best of 3: 126 ms per loop\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ser1 = pd.Series(rands1)\n",
"ser2 = pd.Series(rands2)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%timeit\n",
"\n",
"ser3 = ser1 * ser2"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1 loops, best of 3: 208 ms per loop\n"
]
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment