From e57d55dbc2e9225b01a71f4260b4c0b742c7e2b6 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 15 Nov 2019 10:43:06 -0500 Subject: [PATCH] Adds isin boolean indexing to example (#45) * adds isin example * removes unecessary cells --- example/Online Retail Analysis.ipynb | 152 +++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 10 deletions(-) diff --git a/example/Online Retail Analysis.ipynb b/example/Online Retail Analysis.ipynb index 1cdb001..4b78125 100644 --- a/example/Online Retail Analysis.ipynb +++ b/example/Online Retail Analysis.ipynb @@ -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": [ + "
\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", + " \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", + "
countrycustomer_iddescriptioninvoice_dateinvoice_noquantitystock_codeunit_price
wXcVa24BUkfJ5hz0pRsLUnited Kingdom17850WHITE HANGING HEART T-LIGHT HOLDER2010-12-01 08:26:00536365685123A2.55
wncVa24BUkfJ5hz0pRsLUnited Kingdom17850WHITE METAL LANTERN2010-12-01 08:26:005363656710533.39
w3cVa24BUkfJ5hz0pRsLUnited Kingdom17850CREAM CUPID HEARTS COAT HANGER2010-12-01 08:26:00536365884406B2.75
xHcVa24BUkfJ5hz0pRsLUnited Kingdom17850KNITTED UNION FLAG HOT WATER BOTTLE2010-12-01 08:26:00536365684029G3.39
xXcVa24BUkfJ5hz0pRsLUnited Kingdom17850RED WOOLLY HOTTIE WHITE HEART2010-12-01 08:26:00536365684029E3.39
\n", + "
\n", + "

5 rows x 8 columns

" + ], + "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": {