Adds isin boolean indexing to example (#45)

* adds isin example
* removes unecessary cells
This commit is contained in:
Michael Hirsch 2019-11-15 10:43:06 -05:00 committed by GitHub
parent 905fba5d0f
commit e57d55dbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 97,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@ -611,7 +611,146 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# add isin example"
"we can also filter the data frame using a list of values."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'terms': {'country': ['Germany', 'United States']}}\n"
]
},
{
"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>country</th>\n",
" <th>customer_id</th>\n",
" <th>description</th>\n",
" <th>invoice_date</th>\n",
" <th>invoice_no</th>\n",
" <th>quantity</th>\n",
" <th>stock_code</th>\n",
" <th>unit_price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>wXcVa24BUkfJ5hz0pRsL</th>\n",
" <td>United Kingdom</td>\n",
" <td>17850</td>\n",
" <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
" <td>2010-12-01 08:26:00</td>\n",
" <td>536365</td>\n",
" <td>6</td>\n",
" <td>85123A</td>\n",
" <td>2.55</td>\n",
" </tr>\n",
" <tr>\n",
" <th>wncVa24BUkfJ5hz0pRsL</th>\n",
" <td>United Kingdom</td>\n",
" <td>17850</td>\n",
" <td>WHITE METAL LANTERN</td>\n",
" <td>2010-12-01 08:26:00</td>\n",
" <td>536365</td>\n",
" <td>6</td>\n",
" <td>71053</td>\n",
" <td>3.39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>w3cVa24BUkfJ5hz0pRsL</th>\n",
" <td>United Kingdom</td>\n",
" <td>17850</td>\n",
" <td>CREAM CUPID HEARTS COAT HANGER</td>\n",
" <td>2010-12-01 08:26:00</td>\n",
" <td>536365</td>\n",
" <td>8</td>\n",
" <td>84406B</td>\n",
" <td>2.75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>xHcVa24BUkfJ5hz0pRsL</th>\n",
" <td>United Kingdom</td>\n",
" <td>17850</td>\n",
" <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n",
" <td>2010-12-01 08:26:00</td>\n",
" <td>536365</td>\n",
" <td>6</td>\n",
" <td>84029G</td>\n",
" <td>3.39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>xXcVa24BUkfJ5hz0pRsL</th>\n",
" <td>United Kingdom</td>\n",
" <td>17850</td>\n",
" <td>RED WOOLLY HOTTIE WHITE HEART</td>\n",
" <td>2010-12-01 08:26:00</td>\n",
" <td>536365</td>\n",
" <td>6</td>\n",
" <td>84029E</td>\n",
" <td>3.39</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
"<p>5 rows x 8 columns</p>"
],
"text/plain": [
" country customer_id \\\n",
"wXcVa24BUkfJ5hz0pRsL United Kingdom 17850 \n",
"wncVa24BUkfJ5hz0pRsL United Kingdom 17850 \n",
"w3cVa24BUkfJ5hz0pRsL United Kingdom 17850 \n",
"xHcVa24BUkfJ5hz0pRsL United Kingdom 17850 \n",
"xXcVa24BUkfJ5hz0pRsL United Kingdom 17850 \n",
"\n",
" description invoice_date \\\n",
"wXcVa24BUkfJ5hz0pRsL WHITE HANGING HEART T-LIGHT HOLDER 2010-12-01 08:26:00 \n",
"wncVa24BUkfJ5hz0pRsL WHITE METAL LANTERN 2010-12-01 08:26:00 \n",
"w3cVa24BUkfJ5hz0pRsL CREAM CUPID HEARTS COAT HANGER 2010-12-01 08:26:00 \n",
"xHcVa24BUkfJ5hz0pRsL KNITTED UNION FLAG HOT WATER BOTTLE 2010-12-01 08:26:00 \n",
"xXcVa24BUkfJ5hz0pRsL RED WOOLLY HOTTIE WHITE HEART 2010-12-01 08:26:00 \n",
"\n",
" invoice_no quantity stock_code unit_price \n",
"wXcVa24BUkfJ5hz0pRsL 536365 6 85123A 2.55 \n",
"wncVa24BUkfJ5hz0pRsL 536365 6 71053 3.39 \n",
"w3cVa24BUkfJ5hz0pRsL 536365 8 84406B 2.75 \n",
"xHcVa24BUkfJ5hz0pRsL 536365 6 84029G 3.39 \n",
"xXcVa24BUkfJ5hz0pRsL 536365 6 84029E 3.39 \n",
"\n",
"[5 rows x 8 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(df['country'].isin(['Germany', 'United States']))\n",
"df[df['country'].isin(['Germany', 'United Kingdom'])].head(5)"
]
},
{
@ -1072,13 +1211,6 @@
" (df['unit_price']>0) & \n",
" (df['unit_price']<100)].select_dtypes(include=[np.number]).hist(figsize=[12,4], bins=30)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {