Skip to content

Commit b79579e

Browse files
committed
added pdbc installation steps\
1 parent 3afbad9 commit b79579e

File tree

3 files changed

+300
-10
lines changed

3 files changed

+300
-10
lines changed

Diff for: 02_Type_System/03_StringsDatatype.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ IndexError: string index out of range
8888

8989
`Note`: If we are trying to access characters of a string with out of range index then we will get error saying : IndexError
9090

91-
9291
Accesing from (-)ve index
9392

9493
```python-repl
@@ -102,16 +101,12 @@ Output
102101
''
103102
```
104103

105-
106-
107-
It will return empty string
104+
It will return empty string
108105

109106
Slicing works like this: `String[start:stop:step]`. **When you slice from a higher index to a lower index, the default step is `1`, so it can't go backwards unless you specify a negative step.**
110107

111108
So `num[-2:-6]` essentially means “start at the second-to-last element and go up to, but not including, the sixth-to-last element,” but since it can't move backwards with the default step, it returns nothing.
112109

113-
114-
115110
To slice backwards, use a negative step:
116111

117112
```python
@@ -121,8 +116,6 @@ print(num[-2:-6:-1])
121116
# Outputs: [8, 7, 6, 5]
122117
```
123118

124-
125-
126119
# Assignment
127120

128121
1.Write a program to accept some string from the keyboard and display its characters by index wise(both positive and nEgative index)
@@ -170,7 +163,7 @@ Eg:
170163
- if +ve then it should be forward direction(left to right) and we have to consider begin to end-1
171164
- if -ve then it should be backward direction(right to left) and we have to consider begin to end+1
172165

173-
*** Note:
166+
**Note**:
174167

175168
- In the backward direction if end value is -1 then result is always empty.
176169
- In the forward direction if end value is 0 then result is always empty.
@@ -231,7 +224,7 @@ Python contains the following methods for this purpose.
231224
6) istitle(): Returns True if string is in title case
232225
7) isspace(): Returns True if string contains only spaces
233226

234-
```
227+
```python
235228
s=input("Enter any character:")
236229
if s.isalnum():
237230
print("Alpha Numeric Character")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "1cd5a9d5-72e2-4325-81a3-123299be6152",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"# Installing libraries\n",
11+
"!pip install ipython-sql\n",
12+
"\n",
13+
"!pip install prettytable==0.7.2\n",
14+
"\n",
15+
"# Driver \n",
16+
"!pip install mysql-connector-python"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"id": "6acdeab0-6c0f-4dc8-926f-d149ca81df6e",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": []
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 13,
30+
"id": "0f5f9df9-cad7-467a-acba-679c3531a09d",
31+
"metadata": {},
32+
"outputs": [
33+
{
34+
"name": "stdout",
35+
"output_type": "stream",
36+
"text": [
37+
"The sql extension is already loaded. To reload it, use:\n",
38+
" %reload_ext sql\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"#\n",
44+
"\n",
45+
"%load_ext sql\n",
46+
"%sql mysql+mysqlconnector://root:root@localhost/"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"id": "88683ce2-7b2d-4508-bfcf-02708b12c45c",
53+
"metadata": {},
54+
"outputs": [],
55+
"source": []
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": 9,
60+
"id": "6148f2d7-bee2-43df-92c8-00f83d139f50",
61+
"metadata": {},
62+
"outputs": [
63+
{
64+
"name": "stdout",
65+
"output_type": "stream",
66+
"text": [
67+
" * mysql+mysqlconnector://root:***@localhost/\n",
68+
"(mysql.connector.errors.ProgrammingError) 1046 (3D000): No database selected\n",
69+
"[SQL: show tables;]\n",
70+
"(Background on this error at: https://sqlalche.me/e/20/f405)\n"
71+
]
72+
}
73+
],
74+
"source": [
75+
"%%sql\n",
76+
"show tables;"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": null,
82+
"id": "6302cd5e-a7d8-489c-b1c9-9f37c3940f8a",
83+
"metadata": {},
84+
"outputs": [],
85+
"source": []
86+
}
87+
],
88+
"metadata": {
89+
"kernelspec": {
90+
"display_name": "Python 3 (ipykernel)",
91+
"language": "python",
92+
"name": "python3"
93+
},
94+
"language_info": {
95+
"codemirror_mode": {
96+
"name": "ipython",
97+
"version": 3
98+
},
99+
"file_extension": ".py",
100+
"mimetype": "text/x-python",
101+
"name": "python",
102+
"nbconvert_exporter": "python",
103+
"pygments_lexer": "ipython3",
104+
"version": "3.12.4"
105+
}
106+
},
107+
"nbformat": 4,
108+
"nbformat_minor": 5
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
2+
3+
# Setting Up JupyterLab with Database Connections
4+
5+
This guide will walk you through the process of installing JupyterLab, setting up database drivers, and running SQL queries for MySQL, PostgreSQL, SQLite, MongoDB, and SQLAlchemy.
6+
7+
## Prerequisites
8+
- Ensure you have Python installed on your system.
9+
- Install any Database like mysql,postgresql,mongodb..
10+
11+
## Installation
12+
13+
- Open your terminal and run the below commands.
14+
- If your using mac repalce pip with pip3 and python with python3
15+
16+
### Step 1: Install JupyterLab
17+
First, you need to install JupyterLab using pip:
18+
19+
```bash
20+
pip install jupyterlab
21+
```
22+
23+
### step 2: Start JupyterLab with:
24+
25+
```
26+
jupyter lab
27+
```
28+
29+
### 3. Installing SQL module in the notebook
30+
31+
```
32+
pip install ipython-sql
33+
34+
```
35+
36+
## Based on your database install sql drivers
37+
38+
### 1.Mysql
39+
40+
### Installing the mysql in notebook
41+
42+
```
43+
pip install mysql-connector-python
44+
```
45+
46+
47+
### Loading the mysql in the notebook
48+
49+
```
50+
# Load the SQL extension
51+
%load_ext sql
52+
53+
# Set the connection string
54+
55+
%sql mysql+mysqlconnector://your_username:your_password@localhost/your_database
56+
# replace your_database with your sql database name
57+
```
58+
59+
### example:
60+
61+
```
62+
%load_ext sql
63+
%sql mysql+mysqlconnector://root:root@localhost/test # here test is the database name
64+
```
65+
66+
### Now run magic command %%sql for every shell
67+
68+
```
69+
%%sql
70+
71+
```
72+
### Example : if you want to run any sql command first we need to start including %%sql and following query
73+
74+
```
75+
%%sql
76+
SHOW TABLES;
77+
```
78+
79+
80+
### 2. Postgresql
81+
82+
### 1.Install the postgresql
83+
84+
```
85+
pip install psycopg2-binary ipython-sql
86+
87+
```
88+
89+
90+
### 2 Connecting the driver
91+
```
92+
# Format
93+
# Load the SQL extension
94+
95+
%load_ext sql
96+
97+
# Set the connection string
98+
%sql postgresql://your_username:your_password@localhost/your_database
99+
100+
```
101+
102+
# Example format
103+
```
104+
%load_ext sql
105+
%sql postgresql://postgres:password123@localhost/dvdrental
106+
```
107+
108+
- dialect+driver in this case would just be postgresql , but feel free to use a different database software here.
109+
- username:password is where you will substitute your username and password.
110+
- host is usually just localhost.
111+
- In my experience, port does not need to be specified.
112+
- database is the name of the database to connect to.
113+
114+
115+
### 3. Sqlite
116+
117+
### Install the sqlite
118+
119+
```
120+
pip install sqlite ipython-sql
121+
```
122+
123+
### Connect the sqlite
124+
125+
```
126+
# Load the SQL extension
127+
%load_ext sql
128+
129+
# Set the connection string
130+
%sql sqlite:///your_database.db
131+
132+
```
133+
134+
### 4. Mongodb
135+
136+
137+
### Install the Mongodb
138+
```
139+
pip install pymongo
140+
141+
```
142+
143+
144+
### Connecting the Mongodb
145+
146+
```
147+
from pymongo import MongoClient
148+
149+
# Connect to MongoDB
150+
client = MongoClient('mongodb://localhost:27017/')
151+
db = client.your_database
152+
153+
# Run a sample query
154+
print(db.your_collection.find_one())
155+
156+
```
157+
158+
159+
### SQLAlchemy
160+
161+
162+
#### Install SqlAlchemy
163+
164+
```
165+
pip install sqlalchemy ipython-sql
166+
167+
```
168+
169+
### Connect the sqlAlchemy
170+
171+
```
172+
from sqlalchemy import create_engine
173+
174+
# Set the connection string
175+
engine = create_engine('postgresql://your_username:your_password@localhost/your_database')
176+
177+
# Run a sample query
178+
connection = engine.connect()
179+
result = connection.execute("SELECT * FROM your_table")
180+
for row in result:
181+
print(row)
182+
connection.close()
183+
184+
```
185+
186+
187+
188+

0 commit comments

Comments
 (0)