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
145 changes: 0 additions & 145 deletions exercicios/para-sala/Banco de dados.ipynb

This file was deleted.

Empty file added exercicios/para-sala/arquivo.pd
Empty file.
Binary file not shown.
182 changes: 182 additions & 0 deletions exercicios/para-sala/bdprojetoguiado.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3fb51551",
"metadata": {},
"source": [
"## Banco de dados"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6f065d6e",
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"import sqlite3"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a7aa9973",
"metadata": {},
"outputs": [],
"source": [
"file = open(\"demolitions_pse_isr_conflict_2004-01_to_2023-08.csv\", encoding= 'UTF-8') "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "eaaee9c6",
"metadata": {},
"outputs": [],
"source": [
"conteudo = csv.reader(\"demolitions_pse_isr_conflict_2004-01_to_2023-08.csv\")\n",
"\n",
"connection = sqlite3.connect(\"banco_estruturasDemolidas.db\")\n",
"\n",
"cursor = connection.cursor()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "25d07ce5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sqlite3.Cursor at 0x2313a40bb40>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"cursor.execute('''CREATE TABLE IF NOT EXISTS rank (\n",
" Locality VARCHAR,\n",
" District VARCHAR,\n",
" Housing_Units VARCHAR, \n",
" People_left_homeless INT,\n",
" Minors_left_homeless INT,\n",
" Type_of_structure VARCHAR,\n",
" Reason_for_demolition VARCHAR\n",
" \n",
")''')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "8a047292",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sqlite3.Cursor at 0x2313a40bb40>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"inserir_conteudo = \"INSERT INTO rank (Locality,District,Housing_Units,People_left_homeless,Minors_left_homeless,Type_of_structure,Reason_for_demolition)VALUES(?, ?, ?, ?, ?, ?, ?)\"\n",
"Locality = \"Localidade\"\n",
"District = \"Distrito\"\n",
"Housing_Units = \"Unidade Habitacional\"\n",
"People_left_homeless = 5763\n",
"Minors_left_homeless = 5763\n",
"Type_of_structure = \"Tipo de Estrutura\"\n",
"Reason_for_demolition = \"Motivo\"\n",
"\n",
"valores = (Locality, District, Housing_Units, People_left_homeless, Minors_left_homeless, Type_of_structure, Reason_for_demolition)\n",
"\n",
"cursor.executemany(inserir_conteudo, [valores])\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "51ed46b3",
"metadata": {},
"outputs": [],
"source": [
"selecionar_tudo = \"SELECT * FROM rank\"\n",
"entradas = cursor.execute(selecionar_tudo).fetchall()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "f30ba732",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('Localidade', 'Distrito', 'Unidade Habitacional', 5763, 5763, 'Tipo de Estrutura', 'Motivo')\n"
]
}
],
"source": [
"for entrada in entradas:\n",
" print(entrada)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7dcca72",
"metadata": {},
"outputs": [],
"source": [
"connection.commit()\n",
"connection.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "676a9111",
"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.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading