{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2024-11-18T17:27:45.765230Z", "start_time": "2024-11-18T17:27:43.764041Z" } }, "source": [ "import pandas as pd\n", "from googleapiclient.errors import HttpError\n", "\n", "df = pd.read_excel('demo.xlsx')" ], "outputs": [], "execution_count": 2 }, { "metadata": { "ExecuteTime": { "end_time": "2024-11-18T18:29:32.919196Z", "start_time": "2024-11-18T18:29:32.841076Z" } }, "cell_type": "code", "source": "df", "id": "3fc9b282a2a5215d", "outputs": [ { "ename": "KeyError", "evalue": "'impression'", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mKeyError\u001B[0m Traceback (most recent call last)", "File \u001B[0;32m/opt/anaconda3/lib/python3.11/site-packages/pandas/core/indexes/base.py:3805\u001B[0m, in \u001B[0;36mIndex.get_loc\u001B[0;34m(self, key)\u001B[0m\n\u001B[1;32m 3804\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m-> 3805\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_engine\u001B[38;5;241m.\u001B[39mget_loc(casted_key)\n\u001B[1;32m 3806\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m err:\n", "File \u001B[0;32mindex.pyx:167\u001B[0m, in \u001B[0;36mpandas._libs.index.IndexEngine.get_loc\u001B[0;34m()\u001B[0m\n", "File \u001B[0;32mindex.pyx:196\u001B[0m, in \u001B[0;36mpandas._libs.index.IndexEngine.get_loc\u001B[0;34m()\u001B[0m\n", "File \u001B[0;32mpandas/_libs/hashtable_class_helper.pxi:7081\u001B[0m, in \u001B[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001B[0;34m()\u001B[0m\n", "File \u001B[0;32mpandas/_libs/hashtable_class_helper.pxi:7089\u001B[0m, in \u001B[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001B[0;34m()\u001B[0m\n", "\u001B[0;31mKeyError\u001B[0m: 'impression'", "\nThe above exception was the direct cause of the following exception:\n", "\u001B[0;31mKeyError\u001B[0m Traceback (most recent call last)", "Cell \u001B[0;32mIn[21], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m df[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mimpression\u001B[39m\u001B[38;5;124m'\u001B[39m] \u001B[38;5;241m=\u001B[39m df[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mimpression\u001B[39m\u001B[38;5;124m'\u001B[39m]\u001B[38;5;241m.\u001B[39mstr\u001B[38;5;241m.\u001B[39mreplace(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m,\u001B[39m\u001B[38;5;124m'\u001B[39m, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124m'\u001B[39m)\u001B[38;5;241m.\u001B[39mastype(\u001B[38;5;28mint\u001B[39m)\n", "File \u001B[0;32m/opt/anaconda3/lib/python3.11/site-packages/pandas/core/frame.py:4102\u001B[0m, in \u001B[0;36mDataFrame.__getitem__\u001B[0;34m(self, key)\u001B[0m\n\u001B[1;32m 4100\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcolumns\u001B[38;5;241m.\u001B[39mnlevels \u001B[38;5;241m>\u001B[39m \u001B[38;5;241m1\u001B[39m:\n\u001B[1;32m 4101\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_getitem_multilevel(key)\n\u001B[0;32m-> 4102\u001B[0m indexer \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcolumns\u001B[38;5;241m.\u001B[39mget_loc(key)\n\u001B[1;32m 4103\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m is_integer(indexer):\n\u001B[1;32m 4104\u001B[0m indexer \u001B[38;5;241m=\u001B[39m [indexer]\n", "File \u001B[0;32m/opt/anaconda3/lib/python3.11/site-packages/pandas/core/indexes/base.py:3812\u001B[0m, in \u001B[0;36mIndex.get_loc\u001B[0;34m(self, key)\u001B[0m\n\u001B[1;32m 3807\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(casted_key, \u001B[38;5;28mslice\u001B[39m) \u001B[38;5;129;01mor\u001B[39;00m (\n\u001B[1;32m 3808\u001B[0m \u001B[38;5;28misinstance\u001B[39m(casted_key, abc\u001B[38;5;241m.\u001B[39mIterable)\n\u001B[1;32m 3809\u001B[0m \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;28many\u001B[39m(\u001B[38;5;28misinstance\u001B[39m(x, \u001B[38;5;28mslice\u001B[39m) \u001B[38;5;28;01mfor\u001B[39;00m x \u001B[38;5;129;01min\u001B[39;00m casted_key)\n\u001B[1;32m 3810\u001B[0m ):\n\u001B[1;32m 3811\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m InvalidIndexError(key)\n\u001B[0;32m-> 3812\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mKeyError\u001B[39;00m(key) \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01merr\u001B[39;00m\n\u001B[1;32m 3813\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mTypeError\u001B[39;00m:\n\u001B[1;32m 3814\u001B[0m \u001B[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001B[39;00m\n\u001B[1;32m 3815\u001B[0m \u001B[38;5;66;03m# InvalidIndexError. Otherwise we fall through and re-raise\u001B[39;00m\n\u001B[1;32m 3816\u001B[0m \u001B[38;5;66;03m# the TypeError.\u001B[39;00m\n\u001B[1;32m 3817\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_check_indexing_error(key)\n", "\u001B[0;31mKeyError\u001B[0m: 'impression'" ] } ], "execution_count": 21 }, { "metadata": { "ExecuteTime": { "end_time": "2024-11-18T18:30:20.773902Z", "start_time": "2024-11-18T18:30:20.766806Z" } }, "cell_type": "code", "source": [ "# Grab the Column E\n", "impression_column = df.iloc[:, 4]\n", "total_impressions = impression_column[impression_column.shift(-1).isna()].iloc[0]\n", "\n", "total_impressions\n" ], "id": "76eb4775dda9b64c", "outputs": [ { "data": { "text/plain": [ "71796.3" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 23 }, { "metadata": { "ExecuteTime": { "end_time": "2024-11-18T17:35:53.956689Z", "start_time": "2024-11-18T17:35:53.939722Z" } }, "cell_type": "code", "source": "", "id": "388149da2aba2a39", "outputs": [ { "data": { "text/plain": [ " Addresses Sum of New Road Duration (Mins) \\\n", "27 Total 16041.4 \n", "30 Target (Total Campaigns) 144000 \n", "34 Target (Total Campaigns) 2400 \n", "45 Total 16041.4 \n", "52 Total 16041.4 \n", "59 Total 16041.4 \n", "65 Total 16041.4 \n", "73 Total 16041.4 \n", "80 Total 15180 \n", "88 Total 16041.4 \n", "93 Total 16041.4 \n", "\n", " Sum of New Road Duration (Hours) % Impression %.1 Unnamed: 6 \\\n", "27 267.4 100.0% 71796.3 100.0% NaN \n", "30 100% NaN NaN NaN NaN \n", "34 100 NaN NaN NaN NaN \n", "45 267.4 100.0% 71796.3 100.0% NaN \n", "52 267.4 100.0% 71796.3 100.0% NaN \n", "59 21915.9 115628 400% NaN Total \n", "65 267.4 100.0% 71796.3 100.0% NaN \n", "73 267.4 100.0% 71796.3 100.0% NaN \n", "80 253 100.0% 67497.1 100.0% NaN \n", "88 267.4 100.0% 71796.3 100.0% NaN \n", "93 267.4 100.0% 71796.3 100.0% NaN \n", "\n", " Addresses.1 Sum of Idle Final (Mins) Sum of Idle Final (Hours) %.2 \n", "27 Total 21915.9 365.3 100.0% \n", "30 Idle Time 21915.866667 NaN NaN \n", "34 NaN NaN NaN NaN \n", "45 Total 21915.9 365.3 100.0% \n", "52 Total 21915.9 365.3 100.0% \n", "59 16041.4 21915.9 115628 400% \n", "65 Total 21915.9 365.3 100.0% \n", "73 Total 21915.9 365.3 100.0% \n", "80 Total 21228.8 353.8 100.0% \n", "88 Total 21915.9 365.3 100.0% \n", "93 Total 21915.9 365.3 100.0% " ], "text/html": [ "
| \n", " | Addresses | \n", "Sum of New Road Duration (Mins) | \n", "Sum of New Road Duration (Hours) | \n", "% | \n", "Impression | \n", "%.1 | \n", "Unnamed: 6 | \n", "Addresses.1 | \n", "Sum of Idle Final (Mins) | \n", "Sum of Idle Final (Hours) | \n", "%.2 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|
| 27 | \n", "Total | \n", "16041.4 | \n", "267.4 | \n", "100.0% | \n", "71796.3 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21915.9 | \n", "365.3 | \n", "100.0% | \n", "
| 30 | \n", "Target (Total Campaigns) | \n", "144000 | \n", "100% | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "Idle Time | \n", "21915.866667 | \n", "NaN | \n", "NaN | \n", "
| 34 | \n", "Target (Total Campaigns) | \n", "2400 | \n", "100 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 45 | \n", "Total | \n", "16041.4 | \n", "267.4 | \n", "100.0% | \n", "71796.3 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21915.9 | \n", "365.3 | \n", "100.0% | \n", "
| 52 | \n", "Total | \n", "16041.4 | \n", "267.4 | \n", "100.0% | \n", "71796.3 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21915.9 | \n", "365.3 | \n", "100.0% | \n", "
| 59 | \n", "Total | \n", "16041.4 | \n", "21915.9 | \n", "115628 | \n", "400% | \n", "NaN | \n", "Total | \n", "16041.4 | \n", "21915.9 | \n", "115628 | \n", "400% | \n", "
| 65 | \n", "Total | \n", "16041.4 | \n", "267.4 | \n", "100.0% | \n", "71796.3 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21915.9 | \n", "365.3 | \n", "100.0% | \n", "
| 73 | \n", "Total | \n", "16041.4 | \n", "267.4 | \n", "100.0% | \n", "71796.3 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21915.9 | \n", "365.3 | \n", "100.0% | \n", "
| 80 | \n", "Total | \n", "15180 | \n", "253 | \n", "100.0% | \n", "67497.1 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21228.8 | \n", "353.8 | \n", "100.0% | \n", "
| 88 | \n", "Total | \n", "16041.4 | \n", "267.4 | \n", "100.0% | \n", "71796.3 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21915.9 | \n", "365.3 | \n", "100.0% | \n", "
| 93 | \n", "Total | \n", "16041.4 | \n", "267.4 | \n", "100.0% | \n", "71796.3 | \n", "100.0% | \n", "NaN | \n", "Total | \n", "21915.9 | \n", "365.3 | \n", "100.0% | \n", "