Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exercicio #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
43 changes: 43 additions & 0 deletions LiveLongerData.csv

Large diffs are not rendered by default.

170 changes: 170 additions & 0 deletions exercicios/para-casa/Banco de dados casa.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3fb51551",
"metadata": {},
"source": [
"## Banco de dados"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6f065d6e",
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"import sqlite3"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"file = open(\"estilo_vida.csv\", mode=\"r\", encoding=\"latin-1\")\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "eaaee9c6",
"metadata": {},
"outputs": [],
"source": [
"conteudo = csv.reader(file)\n",
"\n",
"connection = sqlite3.connect(\"Banco1_estilo_vida.db\")\n",
"\n",
"cursor = connection.cursor()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sqlite3.Cursor at 0x16e869da940>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"cursor.execute('''CREATE TABLE IF NOT EXISTS estilo_vida (\n",
" PersonID INT PRIMARY KEY,\n",
" Gender VARCHAR(100),\n",
" Age FLOAT,\n",
" Occupation VARCHAR(100),\n",
" SleepDuration FLOAT,\n",
" \"Quality of Sleep\" FLOAT,\n",
" PhysicalActivityLevel FLOAT,\n",
" StressLevel FLOAT,\n",
" BMICategory VARCHAR(100),\n",
" BloodPressure FLOAT,\n",
" HeartRate FLOAT,\n",
" DailySteps FLOAT,\n",
" SleepDisorder VARCHAR(100)\n",
")''')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"inserir_conteudo = 'INSERT INTO estilo_vida (PersonID, Gender, Age, Occupation, SleepDuration, \"Quality of Sleep\", \"PhysicalActivityLevel\", \"StressLevel\", \"BMICategory\", \"BloodPressure\", \"HeartRate\", \"DailySteps\", \"SleepDisorder\") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'\n",
"\n",
"\n",
"\n",
"\n",
"# Substitua os valores apropriados na variável 'conteudo'\n",
"#conteudo = (1, 'masculino', 30, 'Profissão', 8.0, 4.5, 2.0, 3.0, 'Saudável', 120, 80, 10000, 'Nenhum')\n",
"\n",
"# Execute a instrução de inserção usando seu método de conexão ou cursor\n",
"#cursor.execute(inserir_conteudo, conteudo)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "51ed46b3",
"metadata": {},
"outputs": [],
"source": [
"selecionar_tudo = \"SELECT * FROM estilo_vida\"\n",
"entradas = cursor.execute(selecionar_tudo).fetchall()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f30ba732",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1, 'masculino', 30.0, 'Profissão', 8.0, 4.5, 2.0, 3.0, 'Saudável', 120.0, 80.0, 10000.0, 'Nenhum')\n"
]
}
],
"source": [
"for entrada in entradas:\n",
" print(entrada)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a7dcca72",
"metadata": {},
"outputs": [],
"source": [
"connection.commit()\n",
"connection.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added exercicios/para-casa/Banco1_estilo_vida.db
Binary file not shown.
88,630 changes: 88,630 additions & 0 deletions exercicios/para-casa/Nutrition__Physical_Activity__and_Obesity.csv

Large diffs are not rendered by default.

Loading