From 95e8d822321bf63498fbe9b0701bb1ffb1288a02 Mon Sep 17 00:00:00 2001 From: KatrinaMKaiser Date: Fri, 4 Oct 2024 23:03:34 +0000 Subject: [PATCH] turn sco list wide to long --- ntd/qc_RTPA_contacts.ipynb | 472 +++++++++++++++++++++++++++++++++++++ 1 file changed, 472 insertions(+) create mode 100644 ntd/qc_RTPA_contacts.ipynb diff --git a/ntd/qc_RTPA_contacts.ipynb b/ntd/qc_RTPA_contacts.ipynb new file mode 100644 index 000000000..d89ffdb96 --- /dev/null +++ b/ntd/qc_RTPA_contacts.ipynb @@ -0,0 +1,472 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "dd1a1529-2c99-4067-8020-8ee4d4ab823b", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "from siuba import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "4fc0a143-1c44-4e3c-977e-1a37950571e8", + "metadata": {}, + "outputs": [], + "source": [ + "scolist = pd.read_excel('gs://calitp-analytics-data/data-analyses/ntd/RTPAs Contact Information FY 2021-22.xlsx')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7e78279c-c1ab-45ca-886c-7d02a420e160", + "metadata": {}, + "outputs": [ + { + "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", + " \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", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ENTITY_NAMEFISCAL_YEARCHAIR_FIRST_NAMECHAIR_MICHAIR_LAST_NAMECHAIR_PHONECHAIR_EMAILEXEC_FIRST_NAMEEXEC_MIEXEC_LAST_NAME...FISCAL_OFFICER_MIFISCAL_OFFICER_LAST_NAMEFISCAL_OFFICER_PHONEFISCAL_OFFICER_EMAILSTREET_ADDRESS1STREET_ADDRESS2CITYSTATEZIPADDRESS_CHANGE
0Alpine County Transportation Commission2022DavidNaNGriffith(530) 694-2168dgriffith.9@gmail.comJTNaNChevalier...NaNLeitenbauer(530) 694-2284 ext.134kleitenbauer@alpinecountyca.govAlpine County Community Development50 Diamond Valley RoadMarkleevilleCA96120False
1Amador County Transportation Commission2022PatrickNaNCrew(209) 267-2282pcrew@amadorgov.orgJohnNaNGedney...NaNYakesh(209) 267-2282terri@actc-amador.org117 Valley View WayNaNSutter CreekCA95685False
2Butte County Association of Governments2022JodieNaNJones(530) 538-6834jjones@buttecounty.netJonAClark...PQuinn(530) 809-4616jquinn@bcag.org326 Huss Drive, Suite 150NaNChicoCA95928-8441False
3Calaveras Council of Governments2022AmandaNaNFolendorf(209) 754-2094NaNMichaelNaNAzevedo...NaNNavarro(530) 458-0400agnavarro@countyofcolusa.org546 Jay Street, Suite 202NaNColusaCA95932-2489False
4Colusa County Local Transportation Commission2022FrankNaNKennedy(530) 473-2955 ext.117fkennedy@cityofwilliams.orgMaryNaNGilbert...NaNRivera(831) 637-7665norma@sanbenitocog.org330 Tres Pinos Road, Suite C7NaNHollisterCA95023False
\n", + "

5 rows × 23 columns

\n", + "
" + ], + "text/plain": [ + " ENTITY_NAME FISCAL_YEAR \\\n", + "0 Alpine County Transportation Commission 2022 \n", + "1 Amador County Transportation Commission 2022 \n", + "2 Butte County Association of Governments 2022 \n", + "3 Calaveras Council of Governments 2022 \n", + "4 Colusa County Local Transportation Commission 2022 \n", + "\n", + " CHAIR_FIRST_NAME CHAIR_MI CHAIR_LAST_NAME CHAIR_PHONE \\\n", + "0 David NaN Griffith (530) 694-2168 \n", + "1 Patrick NaN Crew (209) 267-2282 \n", + "2 Jodie NaN Jones (530) 538-6834 \n", + "3 Amanda NaN Folendorf (209) 754-2094 \n", + "4 Frank NaN Kennedy (530) 473-2955 ext.117 \n", + "\n", + " CHAIR_EMAIL EXEC_FIRST_NAME EXEC_MI EXEC_LAST_NAME ... \\\n", + "0 dgriffith.9@gmail.com JT NaN Chevalier ... \n", + "1 pcrew@amadorgov.org John NaN Gedney ... \n", + "2 jjones@buttecounty.net Jon A Clark ... \n", + "3 NaN Michael NaN Azevedo ... \n", + "4 fkennedy@cityofwilliams.org Mary NaN Gilbert ... \n", + "\n", + " FISCAL_OFFICER_MI FISCAL_OFFICER_LAST_NAME FISCAL_OFFICER_PHONE \\\n", + "0 NaN Leitenbauer (530) 694-2284 ext.134 \n", + "1 NaN Yakesh (209) 267-2282 \n", + "2 P Quinn (530) 809-4616 \n", + "3 NaN Navarro (530) 458-0400 \n", + "4 NaN Rivera (831) 637-7665 \n", + "\n", + " FISCAL_OFFICER_EMAIL STREET_ADDRESS1 \\\n", + "0 kleitenbauer@alpinecountyca.gov Alpine County Community Development \n", + "1 terri@actc-amador.org 117 Valley View Way \n", + "2 jquinn@bcag.org 326 Huss Drive, Suite 150 \n", + "3 agnavarro@countyofcolusa.org 546 Jay Street, Suite 202 \n", + "4 norma@sanbenitocog.org 330 Tres Pinos Road, Suite C7 \n", + "\n", + " STREET_ADDRESS2 CITY STATE ZIP ADDRESS_CHANGE \n", + "0 50 Diamond Valley Road Markleeville CA 96120 False \n", + "1 NaN Sutter Creek CA 95685 False \n", + "2 NaN Chico CA 95928-8441 False \n", + "3 NaN Colusa CA 95932-2489 False \n", + "4 NaN Hollister CA 95023 False \n", + "\n", + "[5 rows x 23 columns]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scolist.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "a9244346-f15e-4cba-8aa3-21d75bcad312", + "metadata": {}, + "outputs": [], + "source": [ + "from siuba.experimental.pivot import pivot_wider, pivot_longer\n", + "from siuba import Fx" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "7f206544-e452-4a76-b876-672e080f8df9", + "metadata": {}, + "outputs": [], + "source": [ + "fns = (scolist \n", + " >> select(_.ENTITY_NAME, _.contains(\"_FIRST_NAME\")) \n", + " >> pivot_longer(_.contains(\"_FIRST_NAME\"), names_to=\"position\", values_to=\"first_name\")\n", + " >> mutate(position=_.position.str.replace('_FIRST_NAME', '', regex=False))\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "5c0e0077-c1c3-4a11-b20e-71a4275f092e", + "metadata": {}, + "outputs": [], + "source": [ + "lns = (scolist \n", + " >> select(_.ENTITY_NAME, _.contains(\"_LAST_NAME\")) \n", + " >> pivot_longer(_.contains(\"_LAST_NAME\"), names_to=\"position\", values_to=\"last_name\") \n", + " >> mutate(position=_.position.str.replace('_LAST_NAME', '', regex=False))\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "a2f1a8c0-f261-4ae9-bce2-4715cd5d3bb3", + "metadata": {}, + "outputs": [], + "source": [ + "emails = (scolist \n", + " >> select(_.ENTITY_NAME, _.contains(\"_EMAIL\")) \n", + " >> pivot_longer(_.contains(\"_EMAIL\"), names_to=\"position\", values_to=\"email\") \n", + " >> mutate(position=_.position.str.replace('_EMAIL', '', regex=False))\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "3414acb0-7f1a-4bfc-b47a-103f4a38ebc2", + "metadata": {}, + "outputs": [], + "source": [ + "contact_names = fns.merge(lns).reset_index(drop=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "6fc251f9-c5a7-4f9e-bdc2-85a32b84428d", + "metadata": {}, + "outputs": [], + "source": [ + "contacts = contact_names.merge(emails).reset_index(drop=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "21d0db01-1ebd-444b-b207-cbc91345bd14", + "metadata": {}, + "outputs": [ + { + "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", + "
ENTITY_NAMEpositionfirst_namelast_nameemail
0Alpine County Transportation CommissionCHAIRDavidGriffithdgriffith.9@gmail.com
1Alpine County Transportation CommissionEXECJTChevalierjtchevallier@alpinecountyca.gov
2Alpine County Transportation CommissionFISCAL_OFFICERKlausLeitenbauerkleitenbauer@alpinecountyca.gov
3Amador County Transportation CommissionCHAIRPatrickCrewpcrew@amadorgov.org
4Amador County Transportation CommissionEXECJohnGedneyjohn@actc-amador.org
\n", + "
" + ], + "text/plain": [ + " ENTITY_NAME position first_name \\\n", + "0 Alpine County Transportation Commission CHAIR David \n", + "1 Alpine County Transportation Commission EXEC JT \n", + "2 Alpine County Transportation Commission FISCAL_OFFICER Klaus \n", + "3 Amador County Transportation Commission CHAIR Patrick \n", + "4 Amador County Transportation Commission EXEC John \n", + "\n", + " last_name email \n", + "0 Griffith dgriffith.9@gmail.com \n", + "1 Chevalier jtchevallier@alpinecountyca.gov \n", + "2 Leitenbauer kleitenbauer@alpinecountyca.gov \n", + "3 Crew pcrew@amadorgov.org \n", + "4 Gedney john@actc-amador.org " + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "contacts.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "32402a66-3e55-43fd-9d3f-9387a86ae5b7", + "metadata": {}, + "outputs": [], + "source": [ + "contacts.to_excel(\"gs://calitp-analytics-data/data-analyses/ntd/sco_rtpa_contacts_long.xlsx\", index=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e92c192b-1b49-4226-afc4-6f619f718187", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}