Skip to content

Commit

Permalink
indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
plumeris committed Sep 7, 2021
1 parent 1e3b4c9 commit 85fdee8
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 78 deletions.
129 changes: 90 additions & 39 deletions .ipynb_checkpoints/Connect Python_MySQL-D-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "bae75f73",
"id": "33ee8b59",
"metadata": {},
"source": [
"#### Dataframes list:\n",
Expand Down Expand Up @@ -30,18 +30,20 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 81,
"id": "7d5eb017",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
"import numpy as np\n",
"import seaborn as sns\n",
"import matplotlib as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 77,
"id": "5829c50a",
"metadata": {},
"outputs": [],
Expand All @@ -50,6 +52,7 @@
"import sqlalchemy as sa\n",
"pd.options.display.max_rows = 10\n",
"\n",
"\n",
"# sqlalchemy is a \"toolkit\" that allows access to SQL databases through python. SQL tables can be queried and directly brought to python objects"
]
},
Expand Down Expand Up @@ -101536,7 +101539,7 @@
{
"cell_type": "code",
"execution_count": 34,
"id": "57d22638",
"id": "9aa02fc1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -101550,7 +101553,7 @@
},
{
"cell_type": "markdown",
"id": "f6de9309",
"id": "00081ac5",
"metadata": {},
"source": [
"----"
Expand Down Expand Up @@ -101591,18 +101594,18 @@
{
"cell_type": "code",
"execution_count": 51,
"id": "09157c37",
"id": "4483baec",
"metadata": {},
"outputs": [],
"source": [
"# removing missing date values\n",
"orders_df.dropna(subset=[\"order_approved_at\",\"order_delivered_carrier_date\",\"order_delivered_customer_date\"],inplace=True)"
"orders_df.dropna(subset=[\"order_purchase_timestamp\",\"order_approved_at\",\"order_delivered_carrier_date\",\"order_delivered_customer_date\",\"order_estimated_delivery_date\"],inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "2d9dec7c",
"id": "c65fa567",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -101738,7 +101741,7 @@
{
"cell_type": "code",
"execution_count": 39,
"id": "7f084a9f",
"id": "33a1071c",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -101748,7 +101751,7 @@
{
"cell_type": "code",
"execution_count": 40,
"id": "fe605f17",
"id": "0be07bdc",
"metadata": {},
"outputs": [
{
Expand All @@ -101769,7 +101772,7 @@
{
"cell_type": "code",
"execution_count": 41,
"id": "d015a01c",
"id": "c6a7907f",
"metadata": {},
"outputs": [
{
Expand All @@ -101790,7 +101793,7 @@
{
"cell_type": "code",
"execution_count": 42,
"id": "247c06b0",
"id": "f844408d",
"metadata": {},
"outputs": [
{
Expand All @@ -101811,7 +101814,7 @@
{
"cell_type": "code",
"execution_count": 43,
"id": "6e7bbe7a",
"id": "d5024e70",
"metadata": {},
"outputs": [
{
Expand All @@ -101832,7 +101835,7 @@
{
"cell_type": "code",
"execution_count": 44,
"id": "d79bc3a1",
"id": "3a4da828",
"metadata": {},
"outputs": [
{
Expand All @@ -101853,7 +101856,7 @@
{
"cell_type": "code",
"execution_count": 45,
"id": "ab23ce0f",
"id": "a2b49561",
"metadata": {},
"outputs": [
{
Expand All @@ -101874,7 +101877,7 @@
{
"cell_type": "code",
"execution_count": 46,
"id": "d2296b46",
"id": "1acd8906",
"metadata": {},
"outputs": [
{
Expand All @@ -101895,7 +101898,7 @@
{
"cell_type": "code",
"execution_count": 47,
"id": "2fe94389",
"id": "123c2b15",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -101952,7 +101955,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "847d35ed",
"id": "0086572c",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -101964,7 +101967,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b2919f91",
"id": "75555832",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -102136,7 +102139,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5eae60f9",
"id": "8cbe2e2f",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -102146,7 +102149,7 @@
{
"cell_type": "code",
"execution_count": 57,
"id": "deb6f240",
"id": "964356e6",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -102156,13 +102159,61 @@
{
"cell_type": "code",
"execution_count": 61,
"id": "b59c1b6b",
"id": "1d567014",
"metadata": {},
"outputs": [],
"source": [
"orders_df = drop_na(orders_df)"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "eefe78fd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"orders_df.isnull().values.any().sum()"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "945bfeb9",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'plt' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-80-72b05e94335e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mfig\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mconstrained_layout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfigsize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m13\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m12\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0max1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_subplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0max2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_subplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0msns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcountplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcustomers_df\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'customer_state'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0max\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0max1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpalette\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'rainbow_r'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mtotal\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcustomers_df\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'customer_state'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'plt' is not defined"
]
}
],
"source": [
"fig = plt.figure(constrained_layout=True, figsize=(13, 12))\n",
"ax1 = fig.add_subplot(gs[0, :])\n",
"ax2 = fig.add_subplot(gs[1, :])\n",
"sns.countplot(x=customers_df['customer_state'], ax=ax1, palette='rainbow_r')\n",
"total = len(customers_df['customer_state'])\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "c55bb1ab",
Expand All @@ -102176,81 +102227,81 @@
{
"cell_type": "code",
"execution_count": 64,
"id": "28f87934",
"id": "ef2d5c70",
"metadata": {},
"outputs": [],
"source": [
"trans_product_df.to_csv('trans_product_df.csv')"
"trans_product_df.to_csv('trans_product_df.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "f90dac5b",
"id": "c9000f67",
"metadata": {},
"outputs": [],
"source": [
"orders_df.to_csv('orders_df.csv')"
"orders_df.to_csv('orders_df.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "f2ba3bca",
"id": "4743fee1",
"metadata": {},
"outputs": [],
"source": [
"customers_df.to_csv('customers_df.csv')"
"customers_df.to_csv('customers_df.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "a0e1692d",
"id": "fdcf6891",
"metadata": {},
"outputs": [],
"source": [
"order_payments_df.to_csv('order_payments_df.csv')"
"order_payments_df.to_csv('order_payments_df.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "5834b478",
"id": "4498813e",
"metadata": {},
"outputs": [],
"source": [
"order_items_df.to_csv('order_items_df.csv')"
"order_items_df.to_csv('order_items_df.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "067fcb4d",
"id": "913ffcd5",
"metadata": {},
"outputs": [],
"source": [
"order_customer_items_paid_df.to_csv('order_customer_items_paid_df.csv')"
"order_customer_items_paid_df.to_csv('order_customer_items_paid_df.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "5c7c9f14",
"id": "a5e13af7",
"metadata": {},
"outputs": [],
"source": [
"cleaned_geo.to_csv('cleaned_geo.csv')"
"cleaned_geo.to_csv('cleaned_geo.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "c5f22a9c",
"id": "a557d72a",
"metadata": {},
"outputs": [],
"source": [
"sellers_df.to_csv('sellers_df.csv')"
"sellers_df.to_csv('sellers_df.csv', index=False)"
]
},
{
Expand Down
Loading

0 comments on commit 85fdee8

Please sign in to comment.