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
2,509 changes: 2,509 additions & 0 deletions casa.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions exercicios/para-casa/.~lock.catsvdogs.csv#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,jessica,jessica-NH4CU03,03.11.2023 17:17,file:///home/jessica/.config/libreoffice/4;
Binary file added exercicios/para-casa/banco_catsvdogs.db
Binary file not shown.
208 changes: 208 additions & 0 deletions exercicios/para-casa/casa-parte2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"import sqlite3"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"file = open(\"catsvdogs.csv\", encoding= 'UTF-8') "
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"conteudo = csv.reader(file)\n",
"\n",
"connection = sqlite3.connect(\"banco_catsvdogs.db\")\n",
"\n",
"cursor = connection.cursor()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sqlite3.Cursor at 0x7f01e85c2140>"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cursor.execute('''CREATE TABLE IF NOT EXISTS rank (\n",
" Location VARCHAR,\n",
" Number_of_Households INT,\n",
" Percentage_of_households_with_pets FLOAT, \n",
" Number_of_Pet_Households INT,\n",
" Percentage_of_Dog_Owners FLOAT,\n",
" Dog_Owning_Households INT,\n",
" Mean_Number_of_Dogs_per_household FLOAT,\n",
" Dog_Population INT,\n",
" Percentage_of_Cat_Owners FLOAT,\n",
" Cat_Owning_Households INT,\n",
" Mean_Number_of_Cats FLOAT,\n",
" Cat_Population INT\n",
" \n",
")''')"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sqlite3.Cursor at 0x7f01e85c2140>"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inserir_conteudo = \"INSERT INTO rank (Location, Number_of_Households, Percentage_of_households_with_pets, Number_of_Pet_Households, Percentage_of_Dog_Owners, Dog_Owning_Households, Mean_Number_of_Dogs_per_household, Dog_Population, Percentage_of_Cat_Owners, Cat_Owning_Households, Mean_Number_of_Cats, Cat_Population)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\"\n",
"\n",
"cursor.executemany(inserir_conteudo, conteudo)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"selecionar_tudo = \"SELECT * FROM rank\"\n",
"entradas = cursor.execute(selecionar_tudo).fetchall()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('Location', 'Number of Households (in 1000)', 'Percentage of households with pets', 'Number of Pet Households (in 1000)', 'Percentage of Dog Owners', 'Dog Owning Households (1000s)', 'Mean Number of Dogs per household', 'Dog Population (in 1000)', 'Percentage of Cat Owners', 'Cat Owning Households', 'Mean Number of Cats', 'Cat Population')\n",
"('Alabama', 1828, 59.5, 1088, 44.1, 807, 1.7, 141, 27.4, 501, 2.5, 1252)\n",
"('Arizona', 2515, 59.5, 1497, 40.1, 1008, 1.8, 1798, 29.6, 743, 1.9, 1438)\n",
"('Arkansas', 1148, 62.4, 716, 47.9, 550, 2.0, 1097, 30.6, 351, 2.3, 810)\n",
"('California', 12974, 52.9, 6865, 32.8, 426, 1.6, 6687, 28.3, 3687, 1.9, 7118)\n",
"('Colorado', 1986, 61.3, 1217, 42.5, 845, 1.6, 1349, 32.3, 642, 1.9, 1191)\n",
"('Connecticut', 1337, 54.4, 728, 28.3, 379, 1.3, 507, 31.9, 427, 1.9, 796)\n",
"('Delaware', 334, 56.6, 189, 33.7, 113, 1.4, 163, 33.7, 113, 1.7, 187)\n",
"('District of Columbia', 287, 21.9, 63, 13.1, 38, 1.1, 42, 11.6, 33, 1.9, 63)\n",
"('Florida', 7609, 54.4, 4138, 35.7, 2718, 1.5, 421, 27.3, 2079, 2.1, 4375)\n",
"('Georgia', 3798, 55.1, 2093, 40.1, 1522, 1.6, 2479, 27.3, 1037, 2.1, 2162)\n",
"('Idaho', 568, 62.0, 352, 42.7, 242, 1.5, 357, 34.6, 196, 2.0, 393)\n",
"('Illinois', 5026, 51.8, 2602, 32.4, 1627, 1.5, 2365, 26.3, 1321, 1.9, 2453)\n",
"('Indiana', 2478, 59.9, 1484, 39.9, 989, 1.6, 1619, 34.4, 852, 2.2, 1912)\n",
"('Iowa', 1219, 53.6, 654, 33.4, 407, 1.5, 610, 30.3, 370, 2.2, 805)\n",
"('Kansas', 1133, 61.0, 691, 42.3, 480, 1.6, 774, 33.3, 378, 1.9, 731)\n",
"('Kentucky', 1777, 61.6, 1094, 45.9, 816, 1.9, 1531, 36.8, 654, 2.1, 1349)\n",
"('Louisiana', 1702, 55.1, 937, 36.4, 619, 1.8, 1115, 25.9, 441, 2.0, 877)\n",
"('Maine', 548, 62.9, 345, 34.6, 190, 1.6, 300, 46.4, 254, 1.9, 498)\n",
"('Maryland', 2169, 52.3, 1134, 30.8, 667, 1.4, 915, 29.8, 645, 2.6, 1677)\n",
"('Massachusetts', 2618, 50.4, 1318, 23.6, 618, 1.4, 850, 34.1, 892, 1.8, 1593)\n",
"('Michigan', 3804, 55.4, 2108, 34.6, 1318, 1.5, 2036, 31.3, 1192, 2.0, 242)\n",
"('Minnesota', 2163, 53.0, 1146, 31.9, 690, 1.4, 934, 29.7, 643, 2.0, 1264)\n",
"('Mississippi', 1115, 56.4, 629, 45.2, 504, 1.7, 846, 29.1, 324, 2.1, 668)\n",
"('Missouri', 2498, 61.4, 1534, 45.9, 1148, 1.7, 1978, 32.2, 805, 2.1, 1653)\n",
"('Montana', 410, 61.3, 251, 41.2, 169, 1.7, 282, 33.6, 138, 2.0, 277)\n",
"('Nebraska', 710, 51.3, 364, 33.8, 240, 1.6, 374, 31.3, 222, 2.3, 514)\n",
"('Nevada', 986, 55.6, 548, 37.1, 366, 1.6, 578, 30.3, 299, 2.1, 625)\n",
"('New Hampshire', 508, 56.8, 289, 30.3, 154, 1.4, 212, 34.2, 174, 1.8, 309)\n",
"('New Jersey', 3177, 50.7, 1611, 32.4, 1028, 1.3, 134, 25.3, 803, 1.8, 1468)\n",
"('New Mexico', 773, 67.6, 523, 46.0, 356, 2.0, 703, 32.0, 247, 2.2, 533)\n",
"('New York', 7512, 50.6, 3802, 29.0, 2177, 1.4, 3054, 29.1, 2189, 1.9, 4261)\n",
"('North Carolina', 3701, 56.4, 2089, 40.3, 1491, 1.7, 2518, 29.5, 109, 2.0, 2220)\n",
"('North Dakota', 272, 53.9, 147, 36.1, 98, 1.4, 139, 31.4, 85, 2.0, 174)\n",
"('Ohio', 4661, 57.4, 2677, 36.6, 1708, 1.6, 273, 33.3, 1553, 2.4, 3786)\n",
"('Oklahoma', 1479, 58.9, 872, 43.2, 638, 2.1, 1327, 32.6, 482, 2.2, 1041)\n",
"('Oregon', 1505, 63.6, 957, 38.8, 584, 1.6, 917, 40.2, 605, 2.0, 1185)\n",
"('Pennsylvania', 5172, 56.9, 2942, 32.9, 1702, 1.5, 2485, 33.8, 1748, 2.0, 3544)\n",
"('Rhode Island', 434, 53.0, 230, 29.3, 127, 1.3, 161, 27.6, 120, 1.8, 212)\n",
"('South Carolina', 1759, 54.1, 951, 38.6, 678, 1.8, 1191, 27.8, 490, 2.1, 1039)\n",
"('South Dakota', 333, 65.6, 219, 42.8, 143, 1.5, 220, 39.1, 130, 2.2, 290)\n",
"('Tennessee', 2583, 59.6, 154, 44.1, 114, 1.9, 2157, 29.8, 770, 2.3, 1749)\n",
"('Texas', 9002, 58.5, 5265, 44.0, '3,96', 1.8, 7163, 28.3, 2544, 2.2, 5565)\n",
"('Utah', 930, 51.2, 476, 29.4, 273, 1.5, 410, 24.6, 229, 2.0, 455)\n",
"('Vermont', 265, 70.8, 188, 37.7, 100, 1.4, 142, 49.5, 131, 1.8, 234)\n",
"('Virginia', 3017, 53.4, 1611, 35.4, 1069, 1.6, 1699, 29.0, 876, 2.1, 1855)\n",
"('Washington', 2632, 62.7, 1649, 36.3, 954, 1.7, 1609, 39.0, 1028, 1.8, 1844)\n",
"('West Virginia', 765, 62.1, 475, 45.8, 350, 1.8, 648, 38.1, 291, 2.2, 628)\n",
"('Wisconsin', 235, 57.5, 1352, 33.9, 796, 1.4, 1138, 33.0, 776, 1.9, 1510)\n",
"('Wyoming', 221, 61.8, 137, 38.8, 86, 1.5, 125, 33.9, 75, 1.9, 144)\n"
]
}
],
"source": [
"for entrada in entradas:\n",
" print(entrada)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"connection.commit()\n",
"connection.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.0"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
50 changes: 50 additions & 0 deletions exercicios/para-casa/catsvdogs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Location,Number of Households (in 1000),Percentage of households with pets,Number of Pet Households (in 1000),Percentage of Dog Owners,Dog Owning Households (1000s),Mean Number of Dogs per household,Dog Population (in 1000),Percentage of Cat Owners,Cat Owning Households,Mean Number of Cats,Cat Population
Alabama,1828,59.5,1088,44.1,807,1.7,141,27.4,501,2.5,1252
Arizona,2515,59.5,1497,40.1,1008,1.8,1798,29.6,743,1.9,1438
Arkansas,1148,62.4,716,47.9,550,2.0,1097,30.6,351,2.3,810
California,12974,52.9,6865,32.8,426,1.6,6687,28.3,3687,1.9,7118
Colorado,1986,61.3,1217,42.5,845,1.6,1349,32.3,642,1.9,1191
Connecticut,1337,54.4,728,28.3,379,1.3,507,31.9,427,1.9,796
Delaware,334,56.6,189,33.7,113,1.4,163,33.7,113,1.7,187
District of Columbia,287,21.9,63,13.1,38,1.1,42,11.6,33,1.9,63
Florida,7609,54.4,4138,35.7,2718,1.5,421,27.3,2079,2.1,4375
Georgia,3798,55.1,2093,40.1,1522,1.6,2479,27.3,1037,2.1,2162
Idaho,568,62.0,352,42.7,242,1.5,357,34.6,196,2.0,393
Illinois,5026,51.8,2602,32.4,1627,1.5,2365,26.3,1321,1.9,2453
Indiana,2478,59.9,1484,39.9,989,1.6,1619,34.4,852,2.2,1912
Iowa,1219,53.6,654,33.4,407,1.5,610,30.3,370,2.2,805
Kansas,1133,61.0,691,42.3,480,1.6,774,33.3,378,1.9,731
Kentucky,1777,61.6,1094,45.9,816,1.9,1531,36.8,654,2.1,1349
Louisiana,1702,55.1,937,36.4,619,1.8,1115,25.9,441,2.0,877
Maine,548,62.9,345,34.6,190,1.6,300,46.4,254,1.9,498
Maryland,2169,52.3,1134,30.8,667,1.4,915,29.8,645,2.6,1677
Massachusetts,2618,50.4,1318,23.6,618,1.4,850,34.1,892,1.8,1593
Michigan,3804,55.4,2108,34.6,1318,1.5,2036,31.3,1192,2.0,242
Minnesota,2163,53.0,1146,31.9,690,1.4,934,29.7,643,2.0,1264
Mississippi,1115,56.4,629,45.2,504,1.7,846,29.1,324,2.1,668
Missouri,2498,61.4,1534,45.9,1148,1.7,1978,32.2,805,2.1,1653
Montana,410,61.3,251,41.2,169,1.7,282,33.6,138,2.0,277
Nebraska,710,51.3,364,33.8,240,1.6,374,31.3,222,2.3,514
Nevada,986,55.6,548,37.1,366,1.6,578,30.3,299,2.1,625
New Hampshire,508,56.8,289,30.3,154,1.4,212,34.2,174,1.8,309
New Jersey,3177,50.7,1611,32.4,1028,1.3,134,25.3,803,1.8,1468
New Mexico,773,67.6,523,46.0,356,2.0,703,32.0,247,2.2,533
New York,7512,50.6,3802,29.0,2177,1.4,3054,29.1,2189,1.9,4261
North Carolina,3701,56.4,2089,40.3,1491,1.7,2518,29.5,109,2.0,2220
North Dakota,272,53.9,147,36.1,98,1.4,139,31.4,85,2.0,174
Ohio,4661,57.4,2677,36.6,1708,1.6,273,33.3,1553,2.4,3786
Oklahoma,1479,58.9,872,43.2,638,2.1,1327,32.6,482,2.2,1041
Oregon,1505,63.6,957,38.8,584,1.6,917,40.2,605,2.0,1185
Pennsylvania,5172,56.9,2942,32.9,1702,1.5,2485,33.8,1748,2.0,3544
Rhode Island,434,53.0,230,29.3,127,1.3,161,27.6,120,1.8,212
South Carolina,1759,54.1,951,38.6,678,1.8,1191,27.8,490,2.1,1039
South Dakota,333,65.6,219,42.8,143,1.5,220,39.1,130,2.2,290
Tennessee,2583,59.6,154,44.1,114,1.9,2157,29.8,770,2.3,1749
Texas,9002,58.5,5265,44.0,"3,96",1.8,7163,28.3,2544,2.2,5565
Utah,930,51.2,476,29.4,273,1.5,410,24.6,229,2.0,455
Vermont,265,70.8,188,37.7,100,1.4,142,49.5,131,1.8,234
Virginia,3017,53.4,1611,35.4,1069,1.6,1699,29.0,876,2.1,1855
Washington,2632,62.7,1649,36.3,954,1.7,1609,39.0,1028,1.8,1844
West Virginia,765,62.1,475,45.8,350,1.8,648,38.1,291,2.2,628
Wisconsin,235,57.5,1352,33.9,796,1.4,1138,33.0,776,1.9,1510
Wyoming,221,61.8,137,38.8,86,1.5,125,33.9,75,1.9,144