{ "metadata": { "name": "", "signature": "sha256:81dd4626ee0888046490b916ffd1545e784fff53b4a1e227a9fc9268ddebee06" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Categorical Data In Pandas\n", "\n", "- **Author:** [Chris Albon](http://www.chrisalbon.com/), [@ChrisAlbon](https://twitter.com/chrisalbon)\n", "- **Date:** -\n", "- **Repo:** [Python 3 code snippets for data science](https://github.com/chrisalbon/code_py)\n", "- **Note:**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create a dataframe" ] }, { "cell_type": "code", "collapsed": false, "input": [ "data = {'county': ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma'], \n", " 'year': [2012, 2012, 2013, 2014, 2014], \n", " 'reports': [4, 24, 31, 2, 3]}\n", "df = pd.DataFrame(data)\n", "df" ], "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", "
countyreportsyear
0 Cochice 4 2012
1 Pima 24 2012
2 Santa Cruz 31 2013
3 Maricopa 2 2014
4 Yuma 3 2014
\n", "

5 rows \u00d7 3 columns

\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 38, "text": [ " county reports year\n", "0 Cochice 4 2012\n", "1 Pima 24 2012\n", "2 Santa Cruz 31 2013\n", "3 Maricopa 2 2014\n", "4 Yuma 3 2014\n", "\n", "[5 rows x 3 columns]" ] } ], "prompt_number": 38 } ], "metadata": {} } ] }