Snippets Ipynb
Snippets Ipynb
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"people = {\n",
" 'first': ['Corey', 'Jane', 'John', 'Adam'], \n",
" 'last': ['Schafer', 'Doe', 'Doe', 'Doe'], \n",
" 'email': ['[email protected]', '[email protected]',
'[email protected]', '[email protected]']\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame(people)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>first</th>\n",
" <th>last</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Corey</td>\n",
" <td>Schafer</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Jane</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>John</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Adam</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" first last email\n",
"0 Corey Schafer [email protected]\n",
"1 Jane Doe [email protected]\n",
"2 John Doe [email protected]\n",
"3 Adam Doe [email protected]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>first</th>\n",
" <th>last</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Corey</td>\n",
" <td>Schafer</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Jane</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>John</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Adam</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" first last email\n",
"0 Corey Schafer [email protected]\n",
"1 Jane Doe [email protected]\n",
"2 John Doe [email protected]\n",
"3 Adam Doe [email protected]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.sort_values(by='last', ascending=False)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>first</th>\n",
" <th>last</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Corey</td>\n",
" <td>Schafer</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>John</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Jane</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Adam</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" first last email\n",
"0 Corey Schafer [email protected]\n",
"2 John Doe [email protected]\n",
"1 Jane Doe [email protected]\n",
"3 Adam Doe [email protected]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.sort_values(by=['last', 'first'], ascending=False)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"df.sort_values(by=['last', 'first'], ascending=[False, True], inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>first</th>\n",
" <th>last</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Corey</td>\n",
" <td>Schafer</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Adam</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Jane</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>John</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" first last email\n",
"0 Corey Schafer [email protected]\n",
"3 Adam Doe [email protected]\n",
"1 Jane Doe [email protected]\n",
"2 John Doe [email protected]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>first</th>\n",
" <th>last</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Corey</td>\n",
" <td>Schafer</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Jane</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>John</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Adam</td>\n",
" <td>Doe</td>\n",
" <td>[email protected]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" first last email\n",
"0 Corey Schafer [email protected]\n",
"1 Jane Doe [email protected]\n",
"2 John Doe [email protected]\n",
"3 Adam Doe [email protected]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.sort_index()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3 Doe\n",
"1 Doe\n",
"2 Doe\n",
"0 Schafer\n",
"Name: last, dtype: object"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['last'].sort_values()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}