Skip to content

Instantly share code, notes, and snippets.

@vallantin
Last active August 15, 2018 19:48
Show Gist options
  • Save vallantin/508b71093940e1d577650b8346d7966a to your computer and use it in GitHub Desktop.
Save vallantin/508b71093940e1d577650b8346d7966a to your computer and use it in GitHub Desktop.
Get the frequency of the values on a Data Frame column
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"vegan 4\n",
"not vegan 3\n",
"Name: Eats, dtype: int64"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"info = {\n",
" 'People' : ['John','Mary','Jordan','Patty','Bruce','Bob','Helena'],\n",
" 'Eats' : ['vegan','vegan','not vegan','vegan','not vegan','vegan','not vegan']\n",
"}\n",
"\n",
"columns = ['People','Eats']\n",
"\n",
"df = pd.DataFrame(info, columns=columns)\n",
"\n",
"df.Eats.value_counts()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment