Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions exercicios/para-casa/db_table_visualization.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import sqlite3\n",
"import csv\n",
"\n",
"#CTRL P"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"connection = sqlite3.connect(\"index_inequalidade_genero_mundial.db\")\n",
"cursor = connection.cursor()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(\"./raw_data/Gender_Inequality_Index.csv\", encoding='UTF-8') as file:\n",
" data = csv.reader(file)\n",
" next(data)\n",
" cursor.execute('''CREATE TABLE IF NOT EXISTS inequalidade_genero_mundial (\n",
" Country TEXT,\n",
" Human_development TEXT,\n",
" GII INT,\n",
" Rank REAL,\n",
" Maternal_mortality INT,\n",
" Adolescent_birth_rate REAL,\n",
" Seats_parliament REAL,\n",
" F_secondary_educ REAL,\n",
" M_secondary_educ REAL,\n",
" F_Labour_force REAL,\n",
" M_Labour_force REAL\n",
" )''')\n",
" inserir_conteudo = \"INSERT INTO inequalidade_genero_mundial (Country, Human_development, GII, Rank, Maternal_mortality, Adolescent_birth_rate, Seats_parliament, F_secondary_educ, M_secondary_educ, F_Labour_force, M_Labour_force) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\"\n",
"\n",
" for row in data:\n",
" cursor.execute(inserir_conteudo, row)\n",
"\n",
"# insert delimiter=\";\" as a file attribute in case the .csv has ; instead of , separating the rows"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"connection.commit()\n",
"connection.close()"
]
}
],
"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.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading