{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import eland as ed\n", "from elasticsearch import Elasticsearch" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": "False" }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "es = Elasticsearch()\n", "ed_df = ed.DataFrame('localhost', 'flights', columns = [\"AvgTicketPrice\", \"Cancelled\", \"dayOfWeek\", \"timestamp\", \"DestCountry\"])\n", "es.indices.exists(index=\"churn\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2021-03-30 11:57:39.116425: read 10000 rows\n", "2021-03-30 11:57:39.522722: read 13059 rows\n" ] } ], "source": [ "# NBVAL_IGNORE_OUTPUT\n", "pd_df = ed.eland_to_pandas(ed_df, show_progress=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": "pandas.core.frame.DataFrame" }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(pd_df)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": " account length area code churn customer service calls \\\n0 128 415 0 1 \n1 107 415 0 1 \n\n international plan number vmail messages phone number state \\\n0 no 25 382-4657 KS \n1 no 26 371-7191 OH \n\n total day calls total day charge ... total eve calls total eve charge \\\n0 110 45.07 ... 99 16.78 \n1 123 27.47 ... 103 16.62 \n\n total eve minutes total intl calls total intl charge total intl minutes \\\n0 197.4 3 2.7 10.0 \n1 195.5 3 3.7 13.7 \n\n total night calls total night charge total night minutes voice mail plan \n0 91 11.01 244.7 yes \n1 103 11.45 254.4 yes \n\n[2 rows x 21 columns]", "text/html": "
\n | account length | \narea code | \nchurn | \ncustomer service calls | \ninternational plan | \nnumber vmail messages | \nphone number | \nstate | \ntotal day calls | \ntotal day charge | \n... | \ntotal eve calls | \ntotal eve charge | \ntotal eve minutes | \ntotal intl calls | \ntotal intl charge | \ntotal intl minutes | \ntotal night calls | \ntotal night charge | \ntotal night minutes | \nvoice mail plan | \n
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n128 | \n415 | \n0 | \n1 | \nno | \n25 | \n382-4657 | \nKS | \n110 | \n45.07 | \n... | \n99 | \n16.78 | \n197.4 | \n3 | \n2.7 | \n10.0 | \n91 | \n11.01 | \n244.7 | \nyes | \n
1 | \n107 | \n415 | \n0 | \n1 | \nno | \n26 | \n371-7191 | \nOH | \n123 | \n27.47 | \n... | \n103 | \n16.62 | \n195.5 | \n3 | \n3.7 | \n13.7 | \n103 | \n11.45 | \n254.4 | \nyes | \n
2 rows × 21 columns
" }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# NBVAL_IGNORE_OUTPUT\n", "ed.csv_to_eland(\"./test_churn.csv\", es_client='localhost', es_dest_index='churn', es_refresh=True, index_col=0)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": "{'took': 0,\n 'timed_out': False,\n '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},\n 'hits': {'total': {'value': 2, 'relation': 'eq'},\n 'max_score': 1.0,\n 'hits': [{'_index': 'churn',\n '_id': '0',\n '_score': 1.0,\n '_source': {'state': 'KS',\n 'account length': 128,\n 'area code': 415,\n 'phone number': '382-4657',\n 'international plan': 'no',\n 'voice mail plan': 'yes',\n 'number vmail messages': 25,\n 'total day minutes': 265.1,\n 'total day calls': 110,\n 'total day charge': 45.07,\n 'total eve minutes': 197.4,\n 'total eve calls': 99,\n 'total eve charge': 16.78,\n 'total night minutes': 244.7,\n 'total night calls': 91,\n 'total night charge': 11.01,\n 'total intl minutes': 10.0,\n 'total intl calls': 3,\n 'total intl charge': 2.7,\n 'customer service calls': 1,\n 'churn': 0}}]}}" }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# NBVAL_IGNORE_OUTPUT\n", "es.search(index=\"churn\", size=1)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": "{'acknowledged': True}" }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "es.indices.delete(index='churn', ignore=[400, 404])" ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }