diff --git a/pandas/pandas.ipynb b/pandas/pandas.ipynb
index 7dcd716..ec66649 100644
--- a/pandas/pandas.ipynb
+++ b/pandas/pandas.ipynb
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
- "signature": "sha256:1d166238da27d666eaee4041e79ad7adcc22b6b5ef5d6098ce354d0160c79ba5"
+ "signature": "sha256:59c1808d14cc90fbdffb75e71fc2ec13c01cc1495fab34aa19ab482445ca6801"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -3972,7 +3972,8 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "df_10.sub(ser_10, axis=0)"
+ "df_11 = df_10.sub(ser_10, axis=0)\n",
+ "df_11"
],
"language": "python",
"metadata": {},
@@ -4028,6 +4029,297 @@
}
],
"prompt_number": 77
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "NumPy ufuncs (element-wise array methods) operate on pandas objects:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "df_12 = np.abs(df_11)\n",
+ "df_12"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "html": [
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " a | \n",
+ " b | \n",
+ " c | \n",
+ " d | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 99.451186 | \n",
+ " 98.867789 | \n",
+ " 98.676912 | \n",
+ " 99.999886 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 199.455117 | \n",
+ " 199.274013 | \n",
+ " 199.207350 | \n",
+ " 199.907661 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 299.562413 | \n",
+ " 298.921967 | \n",
+ " 298.690777 | \n",
+ " 299.603233 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 78,
+ "text": [
+ " a b c d\n",
+ "0 99.451186 98.867789 98.676912 99.999886\n",
+ "1 199.455117 199.274013 199.207350 199.907661\n",
+ "2 299.562413 298.921967 298.690777 299.603233"
+ ]
+ }
+ ],
+ "prompt_number": 78
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Apply a function on 1D arrays to each column:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "func_1 = lambda x: x.max() - x.min()\n",
+ "df_12.apply(func_1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 79,
+ "text": [
+ "a 200.111226\n",
+ "b 200.054178\n",
+ "c 200.013864\n",
+ "d 199.603347\n",
+ "dtype: float64"
+ ]
+ }
+ ],
+ "prompt_number": 79
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Apply a function on 1D arrays to each row:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "df_12.apply(func_1, axis=1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 80,
+ "text": [
+ "0 1.322973\n",
+ "1 0.700311\n",
+ "2 0.912456\n",
+ "dtype: float64"
+ ]
+ }
+ ],
+ "prompt_number": 80
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Apply a function and return a DataFrame:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "func_2 = lambda x: Series([x.min(), x.max()], index=['min', 'max'])\n",
+ "df_12.apply(func_2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "html": [
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " a | \n",
+ " b | \n",
+ " c | \n",
+ " d | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " min | \n",
+ " 99.451186 | \n",
+ " 98.867789 | \n",
+ " 98.676912 | \n",
+ " 99.999886 | \n",
+ "
\n",
+ " \n",
+ " max | \n",
+ " 299.562413 | \n",
+ " 298.921967 | \n",
+ " 298.690777 | \n",
+ " 299.603233 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 81,
+ "text": [
+ " a b c d\n",
+ "min 99.451186 98.867789 98.676912 99.999886\n",
+ "max 299.562413 298.921967 298.690777 299.603233"
+ ]
+ }
+ ],
+ "prompt_number": 81
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Apply an element-wise Python function to a DataFrame:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "func_3 = lambda x: '%.2f' %x\n",
+ "df_12.applymap(func_3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "html": [
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " a | \n",
+ " b | \n",
+ " c | \n",
+ " d | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 99.45 | \n",
+ " 98.87 | \n",
+ " 98.68 | \n",
+ " 100.00 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 199.46 | \n",
+ " 199.27 | \n",
+ " 199.21 | \n",
+ " 199.91 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 299.56 | \n",
+ " 298.92 | \n",
+ " 298.69 | \n",
+ " 299.60 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 82,
+ "text": [
+ " a b c d\n",
+ "0 99.45 98.87 98.68 100.00\n",
+ "1 199.46 199.27 199.21 199.91\n",
+ "2 299.56 298.92 298.69 299.60"
+ ]
+ }
+ ],
+ "prompt_number": 82
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Apply an element-wise Python function to a Series:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "df_12['a'].map(func_3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 83,
+ "text": [
+ "0 99.45\n",
+ "1 199.46\n",
+ "2 299.56\n",
+ "Name: a, dtype: object"
+ ]
+ }
+ ],
+ "prompt_number": 83
}
],
"metadata": {}