diff --git a/pandas/pandas.ipynb b/pandas/pandas.ipynb index 6c8c4fd..f8f9780 100644 --- a/pandas/pandas.ipynb +++ b/pandas/pandas.ipynb @@ -4826,6 +4826,306 @@ } ], "prompt_number": 94 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "DataFrames can rank over rows or columns." + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df_13 = DataFrame({'foo' : [7, -5, 7, 4, 2, 0, 4, 7],\n", + " 'bar' : [-5, 4, 2, 0, 4, 7, 7, 8],\n", + " 'baz' : [-1, 2, 3, 0, 5, 9, 9, 5]})\n", + "df_13" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "html": [ + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
barbazfoo
0-5-1 7
1 4 2-5
2 2 3 7
3 0 0 4
4 4 5 2
5 7 9 0
6 7 9 4
7 8 5 7
\n", + "
" + ], + "metadata": {}, + "output_type": "pyout", + "prompt_number": 95, + "text": [ + " bar baz foo\n", + "0 -5 -1 7\n", + "1 4 2 -5\n", + "2 2 3 7\n", + "3 0 0 4\n", + "4 4 5 2\n", + "5 7 9 0\n", + "6 7 9 4\n", + "7 8 5 7" + ] + } + ], + "prompt_number": 95 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Rank a DataFrame over rows:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df_13.rank()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "html": [ + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
barbazfoo
0 1.0 1.0 7.0
1 4.5 3.0 1.0
2 3.0 4.0 7.0
3 2.0 2.0 4.5
4 4.5 5.5 3.0
5 6.5 7.5 2.0
6 6.5 7.5 4.5
7 8.0 5.5 7.0
\n", + "
" + ], + "metadata": {}, + "output_type": "pyout", + "prompt_number": 96, + "text": [ + " bar baz foo\n", + "0 1.0 1.0 7.0\n", + "1 4.5 3.0 1.0\n", + "2 3.0 4.0 7.0\n", + "3 2.0 2.0 4.5\n", + "4 4.5 5.5 3.0\n", + "5 6.5 7.5 2.0\n", + "6 6.5 7.5 4.5\n", + "7 8.0 5.5 7.0" + ] + } + ], + "prompt_number": 96 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Rank a DataFrame over columns:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df_13.rank(axis=1)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "html": [ + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
barbazfoo
0 1.0 2.0 3
1 3.0 2.0 1
2 1.0 2.0 3
3 1.5 1.5 3
4 2.0 3.0 1
5 2.0 3.0 1
6 2.0 3.0 1
7 3.0 1.0 2
\n", + "
" + ], + "metadata": {}, + "output_type": "pyout", + "prompt_number": 97, + "text": [ + " bar baz foo\n", + "0 1.0 2.0 3\n", + "1 3.0 2.0 1\n", + "2 1.0 2.0 3\n", + "3 1.5 1.5 3\n", + "4 2.0 3.0 1\n", + "5 2.0 3.0 1\n", + "6 2.0 3.0 1\n", + "7 3.0 1.0 2" + ] + } + ], + "prompt_number": 97 } ], "metadata": {}