Skip to content

Instantly share code, notes, and snippets.

@ivn951
Last active January 7, 2023 19:07
Show Gist options
  • Save ivn951/520b9f2c4ddd0cf6906628f6b7a1b839 to your computer and use it in GitHub Desktop.
Save ivn951/520b9f2c4ddd0cf6906628f6b7a1b839 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6014e1a5-410d-4e1b-8f1d-73fede85b6ae",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" ID_Provincia ID_Comune Comune\n",
"0 103 103034 Gignese\n",
"1 103 103035 Gravellona Toce\n",
"2 103 103036 Gurro\n",
"3 103 103064 Stresa\n",
"4 103 103032 Germagno\n",
".. ... ... ...\n",
"69 103 103070 Vanzone con San Carlo\n",
"70 103 103061 San Bernardino Verbano\n",
"71 103 103023 Cossogno\n",
"72 103 103038 Loreglia\n",
"73 103 103078 Borgomezzavalle\n",
"\n",
"[74 rows x 3 columns]\n"
]
}
],
"source": [
"# Read Data From Google Sheet\n",
"import pandas as pd\n",
"\n",
"# Google Sheet ID\n",
"gsId = '1nxid0IZNXMO0F5QXGSPAvVy6kfh2dAFc9DPbFgHq5FU'\n",
"\n",
"# Worksheet Name or Tab ID '1472662176'\n",
"wsName = 'comuni_vco' \n",
"\n",
"# Worksheet Range E1:H75\n",
"wsRange = 'E1:H75' \n",
"\n",
"# Set URL\n",
"url = 'https://docs.google.com/spreadsheets/d/{0}/gviz/tq?tqx=out:csv&sheet={1}&range={2}'.format(\n",
" gsId,\n",
" wsName,\n",
" wsRange\n",
")\n",
"\n",
"# Read Data\n",
"df_comuni_vco = pd.read_csv(url) \n",
"\n",
"# Drop unnecessary Columns\n",
"df_comuni_vco = df_comuni_vco.drop(columns=['PRO_COM_T']) \n",
"\n",
"# Resample Columns\n",
"df_comuni_vco.columns=['ID_Provincia','ID_Comune','Comune']\n",
"\n",
"\n",
"print(df_comuni_vco)\n",
"\n"
]
}
],
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment