diff --git a/pandas/pandas.ipynb b/pandas/pandas.ipynb index 29e90d1..e3bee24 100644 --- a/pandas/pandas.ipynb +++ b/pandas/pandas.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:a2c9f032efaa18f3ced5e2f10361f1c25cd23e7f29903af944a52c579903f03d" + "signature": "sha256:0dc910ada47612859f282813d751ef152a62e4d6493b0027ad17a368b35379a0" }, "nbformat": 3, "nbformat_minor": 0, @@ -16,7 +16,8 @@ "\n", "* Series\n", "* DataFrame\n", - "* Reindexing" + "* Reindexing\n", + "* Dropping Entries" ] }, { @@ -2151,7 +2152,8 @@ "cell_type": "code", "collapsed": false, "input": [ - "frame_3.ix[range(0, 7), ['state', 'pop', 'unempl', 'year']]" + "frame_6 = frame_3.ix[range(0, 7), ['state', 'pop', 'unempl', 'year']]\n", + "frame_6" ], "language": "python", "metadata": {}, @@ -2242,6 +2244,183 @@ } ], "prompt_number": 45 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Dropping Entries" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Drop rows from a Series or DataFrame:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "frame_7 = frame_6.drop([0, 1])\n", + "frame_7" + ], + "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", + "
statepopunemplyear
2 VA 5.2 6.0 2014
3 MD 4.0 6.0 2014
4 MD 4.1 6.1 2015
5 NaN NaN NaN NaN
6 NaN NaN NaN NaN
\n", + "

5 rows \u00d7 4 columns

\n", + "
" + ], + "metadata": {}, + "output_type": "pyout", + "prompt_number": 46, + "text": [ + " state pop unempl year\n", + "2 VA 5.2 6.0 2014\n", + "3 MD 4.0 6.0 2014\n", + "4 MD 4.1 6.1 2015\n", + "5 NaN NaN NaN NaN\n", + "6 NaN NaN NaN NaN\n", + "\n", + "[5 rows x 4 columns]" + ] + } + ], + "prompt_number": 46 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Drop columns from a DataFrame:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "frame_7 = frame_7.drop('unempl', axis=1)\n", + "frame_7" + ], + "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", + "
statepopyear
2 VA 5.2 2014
3 MD 4.0 2014
4 MD 4.1 2015
5 NaN NaN NaN
6 NaN NaN NaN
\n", + "

5 rows \u00d7 3 columns

\n", + "
" + ], + "metadata": {}, + "output_type": "pyout", + "prompt_number": 47, + "text": [ + " state pop year\n", + "2 VA 5.2 2014\n", + "3 MD 4.0 2014\n", + "4 MD 4.1 2015\n", + "5 NaN NaN NaN\n", + "6 NaN NaN NaN\n", + "\n", + "[5 rows x 3 columns]" + ] + } + ], + "prompt_number": 47 } ], "metadata": {}