Skip to content

Commit 198f42b

Browse files
Add files via upload
1 parent d3eb0c5 commit 198f42b

File tree

1 file changed

+275
-0
lines changed

1 file changed

+275
-0
lines changed

Diff for: Assignment-20.ipynb

+275
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 15,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"test = \"This is a test of the emergency text system\""
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"file = open(\"test.txt\",\"w+\") \n",
19+
"file.write(test)\n",
20+
"file.close()"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 16,
26+
"metadata": {},
27+
"outputs": [
28+
{
29+
"name": "stdout",
30+
"output_type": "stream",
31+
"text": [
32+
"This is a test of the emergency text system\n"
33+
]
34+
}
35+
],
36+
"source": [
37+
"file1 = open(\"test.txt\",\"r+\") \n",
38+
"print(file1.read())"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {},
45+
"outputs": [],
46+
"source": [
47+
"import sqlite3 as sq\n",
48+
"conn = sq.connect('books.db')\n",
49+
"c = conn.cursor()\n",
50+
"c.execute(\"\"\"CREATE TABLE books(\n",
51+
" title text,\n",
52+
" author text,\n",
53+
" year integer\n",
54+
")\"\"\")\n",
55+
"conn.commit()\n",
56+
"conn.close()"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 1,
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"['title', 'author', 'year']\n",
69+
"['The Weirdstone of Brisingamen', 'Alan Garner', '1960']\n",
70+
"['Perdido Street Station', 'China Miéville', '2000']\n",
71+
"['Thud!', 'Terry Pratchett', '2005']\n",
72+
"['The Spellman Files', 'Lisa Lutz', '2007']\n",
73+
"['Small Gods', 'Terry Pratchett', '1992']\n"
74+
]
75+
}
76+
],
77+
"source": [
78+
"import csv\n",
79+
"with open('books.csv') as csv_file:\n",
80+
" csv_reader = csv.reader(csv_file)\n",
81+
" for line in csv_reader:\n",
82+
" print(line)\n",
83+
" "
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 17,
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"data": {
93+
"text/plain": [
94+
"_csv.reader"
95+
]
96+
},
97+
"execution_count": 17,
98+
"metadata": {},
99+
"output_type": "execute_result"
100+
}
101+
],
102+
"source": [
103+
"type(csv_reader)"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 2,
109+
"metadata": {},
110+
"outputs": [
111+
{
112+
"data": {
113+
"text/html": [
114+
"<div>\n",
115+
"<style scoped>\n",
116+
" .dataframe tbody tr th:only-of-type {\n",
117+
" vertical-align: middle;\n",
118+
" }\n",
119+
"\n",
120+
" .dataframe tbody tr th {\n",
121+
" vertical-align: top;\n",
122+
" }\n",
123+
"\n",
124+
" .dataframe thead th {\n",
125+
" text-align: right;\n",
126+
" }\n",
127+
"</style>\n",
128+
"<table border=\"1\" class=\"dataframe\">\n",
129+
" <thead>\n",
130+
" <tr style=\"text-align: right;\">\n",
131+
" <th></th>\n",
132+
" <th>title</th>\n",
133+
" <th>author</th>\n",
134+
" <th>year</th>\n",
135+
" </tr>\n",
136+
" </thead>\n",
137+
" <tbody>\n",
138+
" <tr>\n",
139+
" <th>0</th>\n",
140+
" <td>The Weirdstone of Brisingamen</td>\n",
141+
" <td>Alan Garner</td>\n",
142+
" <td>1960</td>\n",
143+
" </tr>\n",
144+
" <tr>\n",
145+
" <th>1</th>\n",
146+
" <td>Perdido Street Station</td>\n",
147+
" <td>China Miéville</td>\n",
148+
" <td>2000</td>\n",
149+
" </tr>\n",
150+
" <tr>\n",
151+
" <th>2</th>\n",
152+
" <td>Thud!</td>\n",
153+
" <td>Terry Pratchett</td>\n",
154+
" <td>2005</td>\n",
155+
" </tr>\n",
156+
" <tr>\n",
157+
" <th>3</th>\n",
158+
" <td>The Spellman Files</td>\n",
159+
" <td>Lisa Lutz</td>\n",
160+
" <td>2007</td>\n",
161+
" </tr>\n",
162+
" <tr>\n",
163+
" <th>4</th>\n",
164+
" <td>Small Gods</td>\n",
165+
" <td>Terry Pratchett</td>\n",
166+
" <td>1992</td>\n",
167+
" </tr>\n",
168+
" </tbody>\n",
169+
"</table>\n",
170+
"</div>"
171+
],
172+
"text/plain": [
173+
" title author year\n",
174+
"0 The Weirdstone of Brisingamen Alan Garner 1960\n",
175+
"1 Perdido Street Station China Miéville 2000\n",
176+
"2 Thud! Terry Pratchett 2005\n",
177+
"3 The Spellman Files Lisa Lutz 2007\n",
178+
"4 Small Gods Terry Pratchett 1992"
179+
]
180+
},
181+
"execution_count": 2,
182+
"metadata": {},
183+
"output_type": "execute_result"
184+
}
185+
],
186+
"source": [
187+
"import pandas as pd\n",
188+
"# load the data into a Pandas DataFrame\n",
189+
"users = pd.read_csv('books.csv')\n",
190+
"users"
191+
]
192+
},
193+
{
194+
"cell_type": "code",
195+
"execution_count": 13,
196+
"metadata": {},
197+
"outputs": [
198+
{
199+
"name": "stdout",
200+
"output_type": "stream",
201+
"text": [
202+
"[('The Weirdstone of Brisingamen', 'Alan Garner', 1960), ('Perdido Street Station', 'China Miéville', 2000), ('Thud!', 'Terry Pratchett', 2005), ('The Spellman Files', 'Lisa Lutz', 2007), ('Small Gods', 'Terry Pratchett', 1992), ('The Weirdstone of Brisingamen', 'Alan Garner', 1960), ('Perdido Street Station', 'China Miéville', 2000), ('Thud!', 'Terry Pratchett', 2005), ('The Spellman Files', 'Lisa Lutz', 2007), ('Small Gods', 'Terry Pratchett', 1992)]\n"
203+
]
204+
}
205+
],
206+
"source": [
207+
"import sqlite3 as sq\n",
208+
"conn = sq.connect('awesomebooks.db')\n",
209+
"c = conn.cursor()\n",
210+
"bookdetails = pd.read_csv('books.csv')\n",
211+
"# write the data to a sqlite table\n",
212+
"bookdetails.to_sql('awesomebooks', conn, if_exists='append', index = False)\n",
213+
"conn.commit()\n",
214+
"lm =c.execute('''SELECT * FROM awesomebooks''').fetchall()\n",
215+
"print(lm)\n",
216+
"conn.close()\n"
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": 14,
222+
"metadata": {},
223+
"outputs": [
224+
{
225+
"name": "stdout",
226+
"output_type": "stream",
227+
"text": [
228+
"[('Perdido Street Station', 'China Miéville', 2000), ('Perdido Street Station', 'China Miéville', 2000), ('Small Gods', 'Terry Pratchett', 1992), ('Small Gods', 'Terry Pratchett', 1992), ('The Spellman Files', 'Lisa Lutz', 2007), ('The Spellman Files', 'Lisa Lutz', 2007), ('The Weirdstone of Brisingamen', 'Alan Garner', 1960), ('The Weirdstone of Brisingamen', 'Alan Garner', 1960), ('Thud!', 'Terry Pratchett', 2005), ('Thud!', 'Terry Pratchett', 2005)]\n"
229+
]
230+
}
231+
],
232+
"source": [
233+
"import sqlite3 as sq\n",
234+
"conn = sq.connect('awesomebooks.db')\n",
235+
"c = conn.cursor()\n",
236+
"bookdetails = pd.read_csv('books.csv')\n",
237+
"# write the data to a sqlite table\n",
238+
"lp =c.execute('''SELECT * FROM awesomebooks ORDER BY title''').fetchall()\n",
239+
"print(lp)\n",
240+
"conn.close()"
241+
]
242+
},
243+
{
244+
"cell_type": "code",
245+
"execution_count": null,
246+
"metadata": {},
247+
"outputs": [],
248+
"source": [
249+
"from flask import flask\n",
250+
"from flask_sqlalchemy import SQLAlchemy\n"
251+
]
252+
}
253+
],
254+
"metadata": {
255+
"kernelspec": {
256+
"display_name": "Python 3",
257+
"language": "python",
258+
"name": "python3"
259+
},
260+
"language_info": {
261+
"codemirror_mode": {
262+
"name": "ipython",
263+
"version": 3
264+
},
265+
"file_extension": ".py",
266+
"mimetype": "text/x-python",
267+
"name": "python",
268+
"nbconvert_exporter": "python",
269+
"pygments_lexer": "ipython3",
270+
"version": "3.8.5"
271+
}
272+
},
273+
"nbformat": 4,
274+
"nbformat_minor": 4
275+
}

0 commit comments

Comments
 (0)