Skip to main content

SQL and rest python for Data analysis

SQL (Structured Query Language) की ओर —
ये डेटा हैंडलिंग का अगला स्टेप है, जहाँ हम database से data को fetch, update, delete, filter, aur organize करना सीखते हैं।


💾 SQL क्या है (What is SQL)?

SQL का मतलब है Structured Query Language
ये एक database language है जिसका इस्तेमाल data को store, access, और manage करने के लिए किया जाता है।
जैसे Excel में data sheets होती हैं, वैसे SQL में tables होती हैं।

Type Keyword Use
1️⃣ DDL (Data Definition Language) CREATE, ALTER, DROP Database structure change करने के लिए
2️⃣ DML (Data Manipulation Language) INSERT, UPDATE, DELETE Data change करने के लिए
3️⃣ DQL (Data Query Language) SELECT Data निकालने के लिए
4️⃣ DCL (Data Control Language) GRANT, REVOKE Permission देने या हटाने के लिए
5️⃣ TCL (Transaction Control Language) COMMIT, ROLLBACK Changes को confirm या cancel करने के लिए


Download MY SQL From Google

>>>Lets learn this concept compare with excel
Concept in SQL Excel Equivalent Explanation in Simple Words
🏦 Database 📂 Workbook (File) जैसे Excel में एक .xlsx file होती है जिसमें कई sheets होती हैं, वैसे ही SQL में database होता है जिसमें कई tables होती हैं।
📄 Table 📑 Sheet (Worksheet) एक SQL table = एक Excel sheet; दोनों में rows और columns होते हैं।
📊 Row 📈 Record (Data Row) Excel की हर एक पंक्ति (row) जैसे 2nd row में student का data — SQL में भी वही record कहलाता है।
📏 Column 📋 Field (Header) जैसे Excel में "Name", "Marks", "City" column headers होते हैं, SQL में वही columns कहलाते हैं।
INSERT INTO ✍️ Typing or Adding new row manually Excel में नई row डालते हो, SQL में command चलाकर data insert करते हैं।
🧹 DELETE Row Delete Excel में किसी row को delete करना = SQL में DELETE command।
✏️ UPDATE 🖊️ Cell Edit Excel में cell का value बदलना = SQL में UPDATE command।
🔍 SELECT 🔎 Filter or View Excel में filter या search करते हो = SQL में SELECT command।
🧮 SUM / AVERAGE Functions Excel Formulas Excel में formula लगाते हो, SQL में SUM(), AVG(), COUNT() जैसे aggregate functions लगते हैं।
📑 WHERE Clause 🧩 Filter Condition Excel में “Filter → City = Raipur” जैसा filter लगाते हो, SQL में WHERE city='Raipur' लिखा जाता है।
🧠 JOIN 🔗 VLOOKUP Excel में VLOOKUP से दो sheets जोड़ते हो, SQL में JOIN से दो tables जोड़ते हैं।
🔠 ORDER BY ↕️ Sort (A→Z / Z→A) Excel में sorting जैसे “Marks descending”, SQL में ORDER BY marks DESC
📋 GROUP BY 📊 Pivot Table Excel की pivot table की तरह SQL में GROUP BY का use होता है summary निकालने के लिए।



NOTE: SQL me commands (jaise CREATE, SELECT, FROM, WHERE, etc.) case-sensitive nahi hote.

👉 CREATE DATABASE command का use नया database banane के लिए किया जाता है।

जैसे Excel में तुम नई file (Workbook) बनाते हो —

वैसे ही SQL में तुम नया Database बनाते हो।    >>

CREATE DATABASE database_name;

🔹 यहाँ database_name की जगह तुम अपने database का नाम लिखते हो।
🔹 हर database का नाम unique होना चाहिए।

CREATE DATABASE file_name;

create database school;

CrEaTe DaTaBaSe school;

NOTE: तीनों एक ही काम करेंगे — नया database बनाएंगे। bcse MySQL (Windows) is not case sensitive

📘 Topic: USE Command in SQL


🧩 1️⃣ Meaning (मतलब):

👉 USE command ka use किस database को activate करना है, ये बताने के लिए किया जाता है।

जब तुम SQL में कई databases बनाते हो (जैसे school, company, hospital),
तो system को ये बताना पड़ता है कि अब किस database के अंदर काम करना है

USE file_name;

Ex: USE school;  

📘 Topic: CREATE TABLE Command (Explained with Excel Comparison)


🧩 1️⃣ Meaning (मतलब):

👉 CREATE TABLE command का use किसी database के अंदर नई table बनाने के लिए किया जाता है।

जैसे Excel में तुम नई sheet बनाते हो जिसमें columns और rows होते हैं,
वैसे ही SQL में CREATE TABLE से columns और unke data types define किए जाते हैं।

Ex: 

CREATE TABLE Table_Name(

  Roll_No INT(2),                           Explain👉Roll_No dataType(width of that variable)

  S_Name CHAR(100),                  S_Name dataType(width of that variable),

  Grade CHAR(1)                          Grade dataType(width of that variable)

);

तो यहाँ numbers (जैसे 2, 100, 1) का मतलब है 👉

🔹 1. INT(2) → Integer (Number Type)

  • यहाँ 2 केवल display width होता है (MySQL के पुराने version में)।

  • मतलब: यह बताता है कि कितने digit दिखाने हैं, लेकिन actual value पर कोई limit नहीं लगती।
    ➤ उदाहरण: INT(2) में आप 12, 12345, 999 — सब डाल सकते हो।

  • Modern SQL versions (MySQL 8+, PostgreSQL, SQL Server) में ये (2) ignored होता है — यानी कोई असर नहीं।

✅ इसलिए:
INT(2) और INT(10) दोनों same काम करते हैं — number store करना।


🔹 2. CHAR(100) → Fixed Length String

  • मतलब है कि यह exactly 100 characters तक data store कर सकता है।

  • अगर नाम “Divyanshu” (9 letters) लिखा, तो SQL बाकी जगह spaces से भर देगा (कुल 100)।
    ➤ इसलिए long, fixed-size strings के लिए CHAR use करते हैं।


🔹 3. CHAR(1) → Single Character

  • मतलब सिर्फ 1 letter रखेगा, जैसे ‘A’, ‘B’, ‘C’ (grade के लिए perfect)।

🧠 Topic: SELECT * FROM table;


📘 1. Meaning (मतलब):

👉 यह SQL command table से data निकालने (fetch करने) के लिए use होती है।
यानी database में जो table आपने बनाया है, उसमें जो भी data stored है — उसे देखने के लिए हम SELECT command का use करते हैं।


Keyword Meaning Example
SELECT Data निकालने के लिए use होता है SELECT
* इसका मतलब “सारे columns” होता है यानी table के सारे columns का data दिखाओ
FROM बताता है कि data किस table से लाना है FROM Students;
table_name Table का नाम लिखते हैं जिससे data निकालना है जैसे: Students


🧠 Topic: CREATE DATABASE, CREATE TABLE, INSERT & SELECT

📘 1. CREATE DATABASE

Syntax:

CREATE DATABASE File_Name;

Meaning:
👉 यह command एक नया database बनाता है जिसमें हम tables और data रख सकते हैं।
Database = Excel की तरह एक पूरा workbook होता है।

CREATE DATABASE School;

➡️ अब “School” नाम का database बन गया।

📗 2. USE Database
USE File_Name;   ====Syntax
Meaning:
👉 यह बताता है कि आगे की सारी SQL commands इसी database पर चलेंगी।
(Excel में जैसे कोई sheet चुनते हैं — वैसा ही यह command database select करता है।)

Example:

USE School;

➡️ अब आगे की सारी queries इसी “School” database में चलेंगी।

📙 3. CREATE TABLE

Syntax:

CREATE TABLE table_name ( column1 datatype(size), column2 datatype(size), column3 datatype(size) );

Example:

CREATE TABLE DepartmentTable( sr_no INT(5), department CHAR(100), floorNo INT(2) );
Meaning:
👉 यह command एक table बनाता है जिसका नाम DepartmentTable है।
यह table Excel की तरह rows और columns में data रखेगा।
Column NameData TypeDescription
sr_noINT(5)Serial number (number format)
departmentCHAR(100)Department name (text format)
floorNoINT(2)Floor number (number format)

📒 4. INSERT INTO (Data डालना)

Syntax:

INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);

Example:

INSERT INTO DepartmentTable (sr_no, department, floorNo) VALUES (1, "biology", 2), (2, "math", 3), (3, "physics", 2);

Meaning:
👉 इससे table में data की rows insert होती हैं।

📋 Resulting Table:

sr_nodepartmentfloorNo
1biology2
2math3
3physics2

📔 5. SELECT (Data देखना)

Syntax:

SELECT * FROM table_name;

Meaning:
👉 यह command table का सारा data (rows + columns) दिखाने के लिए use होती है।
* का मतलब — सारे columns।

Example:

SELECT * FROM DepartmentTable;

💡 Extra Tip: हर SQL command के अंत में semicolon ( ; ) लगाना ज़रूरी है। SQL case-insensitive है (यानि CREATE, create, Create — सब same हैं)। Text values हमेशा 'quotes' या "quotes" में लिखो।



SQL Commands Overview

SQL (Structured Query Language) में कई प्रकार के commands होते हैं — जिनसे हम database बनाना, बदलना, delete करना या data insert/update करना जैसे काम करते हैं।

इन्हें दो मुख्य categories में बाँटा जाता है:

  1. DDL (Data Definition Language)

  2. DML (Data Manipulation Language)


🏗️ 1. DDL (Data Definition Language)

👉 ये commands database structure (schema) को define या modify करने के लिए use होते हैं।
इनका काम है database और tables की structure बनाना, बदलना या मिटाना।

Command Full Form Purpose
CREATE Create नया Database या Table बनाना
ALTER Alter Table structure बदलना (column जोड़ना, हटाना, type बदलना आदि)
DROP Drop Database या Table को delete करना
TRUNCATE Truncate Table से सभी data हटाना (structure रहता है)
RENAME Rename Table का नाम बदलना

🧱 ALTER Command in SQL

📘 Definition:

ALTER command SQL की DDL (Data Definition Language) का हिस्सा है।
इसका use किसी existing table की structure को modify (बदलने) के लिए किया जाता है।

यानि जब table बन चुकी हो लेकिन बाद में आपको

  • नया column जोड़ना हो,

  • कोई column हटाना हो,

  • column का नाम या data type बदलना हो,
    तो इसके लिए हम ALTER TABLE का use करते हैं।

🧩 Syntax:

ALTER TABLE table_name <operation>; 👉 यहाँ <operation> मतलब — add, drop, modify या rename करना।

⚙️ 1️⃣ नया column जोड़ने के लिए:

ALTER TABLE Student ADD Age INT(2);
🔍 Explanation: ALTER TABLE Student → existing table का नाम। ADD Age INT(2) → नया column Age जोड़ दिया गया जिसका data type INT है। 🧠 अब Student table में एक नया column “Age” जुड़ जाएगा।

⚙️ 2️⃣ किसी table को delete करने के लिए:

Drop table DepartmentTable;

🔍 Explanation:

  • DROP COLUMN → column को पूरी तरह delete कर देता है।
    ⚠️ इसका data भी मिट जाएगा।

⚙️ 3️⃣ किसी column का नाम बदलने के लिए:

(MySQL में syntax थोड़ा version पर depend करता है — नीचे common वाला है 👇)

ALTER TABLE Student RENAME COLUMN S_Name TO Student_Name;

🔍 Explanation:

अब S_Name column का नाम बदलकर Student_Name हो गया।

⚙️ 4️⃣ किसी column का data type बदलने के लिए:

ALTER TABLE Student MODIFY Grade CHAR(2);

🔍 Explanation:

  • अब Grade column की length 1 से बढ़कर 2 हो गई।
    यानि अब “AA” जैसे दो characters तक store हो सकते हैं।

  • We can change datatype also by using this

⚙️ 5️⃣ Table का नाम बदलने के लिए:

ALTER TABLE Student RENAME TO StudentDetails;

🔍 Explanation:

  • अब table का नाम Student से बदलकर StudentDetails हो गया।

🧱 TRUNCATE Command in SQL

📘 Definition:

TRUNCATE command SQL की DDL (Data Definition Language) का हिस्सा है।
इसका use किसी table का सारा data मिटाने (delete करने) के लिए किया जाता है,
लेकिन table की structure को नहीं हटाता। NOTE: DROP TABLE = Structure + Data dono delte kr deta hai


📘 DML – Data Manipulation Language

🔹 Definition:

DML commands का use database ke data को create, insert, update, delete और retrieve करने के लिए किया जाता है।
इनसे हम table के अंदर मौजूद data पर काम करते हैं,
table की structure पर नहीं (वो DDL commands करते हैं जैसे CREATE, ALTER, DROP)।

Example:

🧱 Command:

CREATE DATABASE DML; USE DML; CREATE TABLE students( student_id INT PRIMARY KEY, name VARCHAR(50), age INT, grade VARCHAR(2) );

🧠 Step-by-Step Explanation:

🥇 1. CREATE DATABASE DML;

👉 यह एक नया Database बनाता है जिसका नाम DML है।
Database को तुम एक folder की तरह समझो, जिसमें tables रखी जाती हैं।

📦 Example:

💽 Database: DML

🥈 2. USE DML;

👉 यह बताता है कि अब हम इसी Database (DML) के अंदर काम करेंगे।
मतलब —

“अब आगे जो भी tables बनेंगी, वो DML database के अंदर ही बनेंगी।”

🥉 3. CREATE TABLE students (...);

👉 यह Command एक नई Table बनाती है जिसका नाम students है।

Table को तुम एक Excel Sheet की तरह समझो जिसमें Columns और Rows होते हैं। 

🔑 PRIMARY KEY Explanation:

  • PRIMARY KEY का मतलब है कि उस column में value दोहराई नहीं जा सकती (unique) और खाली नहीं छोड़ी जा सकती (not null)

  • यहाँ student_id को Primary Key बनाया गया है — इसका मतलब हर student का ID unique होगा।

📘 DML Command: SELECT


🔹 Command Syntax:

SELECT column_name FROM table_name;

🧠 Meaning (मतलब):

SELECT command का उपयोग हम table से data निकालने (fetch करने) के लिए करते हैं।
यानी database से specific information देखने के लिए।

🎯 Example:

SELECT name FROM students; 

👉 इसका मतलब है —

“students” table से सिर्फ़ ‘name’ column का data दिखाओ।”

📘 DML Command – INSERT INTO


🧠 Meaning (मतलब):

INSERT INTO command का उपयोग table में नया data जोड़ने (add करने) के लिए किया जाता है।

यह command DML (Data Manipulation Language) का हिस्सा है,
जो data को insert, update, delete या retrieve करने का काम करती है।

🧾 Syntax (रचना):

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);


📍 Example:

INSERT INTO students(student_id, name, age, grade) VALUES (101, 'Divyanshu', 25, 'A');

💡 Important Points: Columns और values की संख्या बराबर होनी चाहिए। String/text data हमेशा quotes ("") में लिखा जाता है। Numerical data बिना quotes के लिखा जाता है। INSERT INTO केवल data add करता है, structure नहीं बदलता।

It will Add Data at the end 

📘 DML Command – UPDATE


🧠 Meaning (मतलब):

UPDATE command का उपयोग किसी table में मौजूद data को बदलने (modify करने) के लिए किया जाता है।
यानी अगर कोई record पहले से मौजूद है, तो उसकी value को बदलने के लिए UPDATE का इस्तेमाल होता है।

🧾 Syntax (रचना):

UPDATE table_name SET column_name = new_value WHERE condition;

🎯 Command Example: update Students set name = "Hunny" where student_id = 1;

🧩 Explanation:

KeywordMeaning
UPDATE studentsstudents नाम की table को target करो
SET name = "Hunny"name column की value बदलो
WHERE student_id = 1सिर्फ उस row में बदलाव करो जहाँ student_id = 1 है
⚙️ Important Points: UPDATE हमेशा existing data को modify करता है, नया data नहीं जोड़ता। अगर WHERE condition नहीं लगाओगे ⛔ तो पूरी table में वो value बदल जाएगी।

🧠 DML Command – DELETE

🔹 Syntax:

DELETE FROM table_name WHERE condition;

🔹 Example:

DELETE FROM students WHERE student_id = 5;
🔹 Explanation:
  • यह command table से row (record) को delete करता है।
  • ऊपर के example में → वो row delete होगी जिसका student_id = 5 है।
  • अगर आप WHERE condition नहीं लगाओगे, तो पूरी table की सभी rows delete हो जाएंगी

🔹 Important Points:

PointDescription
1️⃣DELETE केवल data (rows) हटाता है, table structure नहीं
2️⃣आप condition लगाकर specific row delete कर सकते हैं
3️⃣Table की structure, columns और constraints same रहते हैं
4️⃣ये DML (Data Manipulation Language) command है
5️⃣DELETE करने के बाद आप ROLLBACK करके data वापस ला सकते हैं (यदि transaction चालू हो)

🧾 Topic: ORDER BY (Ascending Order) — SQL DML Command

🧩 Definition:

👉 ORDER BY clause SQL में data को sort (क्रमबद्ध) करने के लिए इस्तेमाल किया जाता है।
By default, यह data को Ascending Order (छोटे से बड़े) में sort करता है।

🧠 Syntax:

SELECT column_name(s) FROM table_name ORDER BY column_name ASC;
🔹 ASC का मतलब है Ascending Order (default होता है — यानी लिखना optional है)

📊 Example:

SELECT * FROM students ORDER BY age;

या

SELECT * FROM students ORDER BY age ASC;

दोनों commands same output देंगी ✅


🧾 Topic: ORDER BY (Descending Order) — SQL DML Command

🧩 Definition:

👉 ORDER BY clause data को sort करने के लिए use होता है।
अगर हमें data को बड़े से छोटे (Descending Order) में arrange करना हो तो हम DESC keyword लगाते हैं।

🧠 Syntax:

SELECT column_name(s) FROM table_name
ORDER BY column_name DESC;
🔹 DESC = Descending (बड़े से छोटे तक)

📊 Example:

SELECT * FROM students ORDER BY age DESC;

🧾 Topic: ORDER BY Multiple Columns (Grade ASC, Age DESC)

🧠 Command:

SELECT * FROM students ORDER BY grade ASC, age DESC;

🧩 Explanation:

इस command का मतलब है 👇

🔹 पहले grade column को ascending order (A → Z) में arrange करो।
🔹 अगर grade same है, तो उनमें से age को descending order (बड़े से छोटे) में sort करो।


 🧩 Topic: GROUP BY Command (SQL)

🔹 Definition:

GROUP BY command का use तब किया जाता है जब हमें similar values वाले rows को एक group में combine करना हो
और उन पर aggregate function (जैसे — SUM, COUNT, AVG, MAX, MIN) लगाना हो।


SQL – JOINS Notes

1️⃣ Joins ka Matlab

JOIN SQL me do ya zyada tables ke data ko combine karne ke liye use hota hai, usually common column ke basis par (Primary Key / Foreign Key).

2️⃣ Types of Joins 1. INNER JOIN Sirf matching rows ko show karta hai. Agar table1 aur table2 me match nahi hota, to row ignore ho jati hai.

2. LEFT JOIN (LEFT OUTER JOIN) Left table ke sab rows show karta hai, aur matching na hone par right table me NULL aayega.

3. RIGHT JOIN (RIGHT OUTER JOIN) Right table ke sab rows show karta hai, aur matching na hone par left table me NULL aayega.

4. FULL OUTER JOIN Donon tables ke sab rows show karta hai. Matching na hone par respective table me NULL aayega.

5. CROSS JOIN Sab combination ka Cartesian Product banata hai. Rows = table1.rows × table2.rows


-----------PENDING HAI JOINS-----------

🧩 Primary Key (प्राइमरी की)

🔹 Definition:

Primary Key ek unique identifier hoti hai jo har record (row) ko uniquely identify karti hai.
Yani table ke andar kisi bhi row ke liye duplicate ya NULL value nahi hoti.

📘 Key Points: Unique hoti hai – do rows me same primary key nahi ho sakti. NULL allowed nahi hota – har record ke paas valid key honi chahiye. Ek table me sirf ek primary key hoti hai (but wo multiple columns se mil kar ban sakti hai). Primary key automatically index create karti hai — search fast hota hai.



🧩 Foreign Key

🧩 1️⃣ Table: Users CREATE TABLE Users ( UserID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), Email VARCHAR(100) UNIQUE ); 🔍 Explanation: UserID → Primary Key (हर यूजर का यूनिक ID) Email → UNIQUE constraint (कोई दो यूजर एक ही ईमेल से रजिस्टर नहीं कर सकते) बाकी कॉलम: FirstName, LastName → सामान्य जानकारी


Insert Command:

INSERT INTO Users (UserID, FirstName, LastName, Email) VALUES (101, 'Alice', 'Johnson', 'alice@example.com'), (102, 'Bob', 'Smith', 'bob@example.com'), (103, 'Charlie', 'Brown', 'charlie@example.com');


🧩 2️⃣ Table: Accounts

CREATE TABLE Accounts ( AccountID INT PRIMARY KEY, UserID INT, AccountType VARCHAR(20), Balance DECIMAL(10, 2), FOREIGN KEY (UserID) REFERENCES Users(UserID) );

🔍 Explanation: AccountID → Primary Key (हर अकाउंट का यूनिक ID) UserID → Foreign Key (ये Users टेबल के UserID से लिंक है) AccountType → जैसे 'Savings', 'Checking' आदि Balance → अकाउंट में पैसे की राशि FOREIGN KEY (UserID) REFERENCES Users(UserID) 👉 इसका मतलब है कि Accounts टेबल में जो भी UserID है, वो पहले से Users टेबल में मौजूद होना चाहिए।



💾 Insert Command:

INSERT INTO Accounts (AccountID, UserID, AccountType, Balance) VALUES (201, 101, 'Savings', 1000.00), (202, 102, 'Checking', 500.50), (203, 103, 'Savings', 2000.25), (204, 102, 'Savings', 2000.25);

➡️ यानि Bob (UserID 102) के पास दो अकाउंट हैं – एक Checking और एक Savings.
➡️ ये दिखाता है कि एक User के पास कई Accounts हो सकते हैं (One-to-Many Relationship).


📊 Relationship Summary

TableKeyDescription
UsersPrimary Key → UserIDप्रत्येक यूजर की पहचान
AccountsForeign Key → UserIDUserID से Users टेबल को लिंक करता है



📘 SQL Constraint – CHECK Constraint (Notes)

🔹 Definition (परिभाषा):

CHECK Constraint का उपयोग किसी कॉलम में आने वाले data को valid या सीमित (restrict) करने के लिए किया जाता है।
यह सुनिश्चित करता है कि केवल वही values कॉलम में insert हों जो दी गई condition को पूरा करें।

🔹 Syntax (वाक्य-विन्यास):

CREATE TABLE table_name ( column_name datatype CHECK (condition) );

🔹 Example (उदाहरण):

CREATE TABLE Customers ( CustomerID INT PRIMARY KEY, CustomerName VARCHAR(50), PhoneNumber VARCHAR(10) CHECK (LENGTH(PhoneNumber) = 10) );

🧠 Explanation: PhoneNumber कॉलम में केवल 10 अंकों (digits) का नंबर ही डाला जा सकता है। अगर कोई नंबर 10 अंकों से ज्यादा या कम हुआ — → SQL Error देगा और data insert नहीं होगा।

🔹 Advantages (फायदे): गलत data database में insert नहीं हो सकता। डेटा की सटीकता (accuracy) बनी रहती है। Business rules को database level पर लागू किया जा सकता है। Application error कम होते हैं।





🧠 UNIQUE Constraint क्या होता है? 👉 UNIQUE constraint का काम होता है यह सुनिश्चित करना कि किसी कॉलम की value दोहराई (duplicate) न जाए। यानि किसी कॉलम की हर value unique (अलग-अलग) होनी चाहिए।

🧩 1️⃣ Code Explanation

CREATE TABLE Customers ( CustomerID INT PRIMARY KEY, CustomerName VARCHAR(50), PhoneNumber VARCHAR(10) UNIQUE );

📞 इस Example में:

PhoneNumber VARCHAR(10) UNIQUE
इसका मतलब है — दो customers का PhoneNumber कभी भी एक जैसा नहीं हो सकता।

🧾 Insert Commands:

INSERT INTO Customers (CustomerID, CustomerName, PhoneNumber) VALUES (301, 'Customer1', '1234567890'), (302, 'Customer2', '9876543210'), (303, 'Customer3', '5551234567'), (304, 'Customer4', '5551234569');


📘 NULL Key (Notes)

🔹 1️⃣ Definition (परिभाषा):

NULL का अर्थ होता है — कोई मान नहीं (No Value)
यह “Zero” या “Blank” नहीं होता, बल्कि Unknown / Missing Value को दर्शाता है।

🔹 2️⃣ Use (उपयोग): जब किसी कॉलम की वैल्यू अभी पता नहीं हो या खाली छोड़नी हो, तब NULL का उपयोग किया जाता है। यह बताता है कि उस कॉलम में कोई डेटा दर्ज नहीं किया गया है।

🧩 Code Explanation

CREATE TABLE Customers ( CustomerID INT PRIMARY KEY, CustomerName VARCHAR(50), PhoneNumber VARCHAR(10) NOT NULL );


📘 DEFAULT Constraint (Notes)

🔹 1️⃣ Definition (परिभाषा):

DEFAULT Constraint का उपयोग तब किया जाता है जब आप किसी कॉलम के लिए डिफ़ॉल्ट (स्वतः भरने वाली) वैल्यू तय करना चाहते हैं,
ताकि अगर डेटा insert करते समय उस कॉलम के लिए वैल्यू न दी जाए —
तो SQL अपने आप वो default value डाल दे।

🔹 2️⃣ Purpose (उद्देश्य):

👉 यह डेटा एंट्री को आसान और consistent बनाता है।
👉 NULL या missing values से बचने में मदद करता है।


🔹 3️⃣ Syntax (वाक्य रचना):

CREATE TABLE Students ( Student_ID INT PRIMARY KEY, Name VARCHAR(50), City VARCHAR(50) DEFAULT 'Raipur' );

👉 अब अगर आप City की value नहीं डालते, तो SQL अपने आप 'Raipur' डाल देगा।


🔹 4️⃣ Example:

INSERT INTO Students (Student_ID, Name) VALUES (101, 'Divyanshu');

📊 Output:

Student_IDNameCity
101DivyanshuRaipur

🔹 Shortcut याद रखने का तरीका:

🧠 “Value न दो तो default भरो”
यानी — अगर user कुछ नहीं भरता, तो SQL खुद से भर देता है।


📘 Data Cleaning Using Python (Notes) NOTE: REST PYTHON WILL BE SAME AS PER YOUR DATA SCIENCE

import numpy as np import pandas as pd #importing the dataset df = pd.read_csv(r'C:\Users\odivy\Downloads\customer.csv') print(df.head())

🧩 1. Libraries Import Karna

import numpy as np import pandas as pd

🔹 NumPy (np):
यह एक Numerical Library है जो बड़े डेटा arrays और mathematical operations को handle करने के लिए use होती है।
👉 Example: Numbers की calculations या matrix operations करने के लिए।

🔹 Pandas (pd):
यह Data Analysis Library है जो data को Excel sheet की तरह organize करने में help करती है।
👉 इससे हम data को read, clean, filter, modify, और analyze कर सकते हैं।


📂 2. Dataset Import Karna

df = pd.read_csv(r'C:\Users\odivy\Downloads\customer.csv')
🔸 pd.read_csv() → Pandas का function है जो CSV (Comma Separated Values) file को पढ़ता है। 🔸 यह function data को DataFrame में convert करता है। 🔸 DataFrame basically rows और columns का structure होता है, जैसे Excel table। 📍 Parameter Explanation: 'C:\Users\odivy\Downloads\customer.csv' → यह file का location path है। यहाँ r का मतलब raw string है, जिससे Python backslash \ को special character की तरह treat नहीं करता। 👉 इसलिए path सही तरीके से read होता है।

⚠️ Common Error:

अगर file का path या नाम गलत लिखा गया हो, तो Python देगा:
FileNotFoundError: [Errno 2] No such file or directory

🧾 3. Dataset Display Karna

print(df.head())

🔹 df.head() function dataset की पहली 5 rows show करता है।
🔹 इसका use यह check करने के लिए किया जाता है कि data file सही से load हुई है या नहीं।
🔹 Output में तुम्हें columns जैसे दिखेंगे —
CustomerID, ProductID, Gender, Age, Occupation, City, State, Purchase, आदि।

------------------------

print(df.tail()) df.shape df.drop("New",axis = 1, inplace = True)

🧾 1. print(df.tail()) print(df.tail()) 🔹 Explanation: यह function dataset की आखिरी 5 rows show करता है। इससे हम verify करते हैं कि data file के end तक सही तरह से load हुई है या नहीं। Large dataset में यह काफी useful होता है।

🧾 2. df.shape df.shape 🔹 Explanation: यह command बताता है कि dataset में कितनी rows और columns हैं। Output ek tuple के रूप में आता है:

🧾 3. df.drop("New", axis=1, inplace=True)

df.drop("New", axis=1, inplace=True)

🔹 Explanation:

ParameterMeaning
"New"Column name जिसे हटाना है
axis=1बताता है कि column हटाना है (अगर axis=0 होता तो row हटती)
inplace=TrueDataset को permanently modify करता है (नया copy नहीं बनाता)

🧠 Example:
अगर dataset में एक extra column "New" था जो काम का नहीं है,
तो यह command उस column को हटा देगा।

🔸 अगर inplace=False होता (default),
तो original DataFrame safe रहता और नया DataFrame return होता।


🧾 Installing Matplotlib Library

📘 1. pip install matplotlib

pip install matplotlib

🔹 यह command Python में Matplotlib library install करता है।

  • यह internet से library को download करता है और system में add करता है।

  • Matplotlib का use graphs, charts और data visualization के लिए किया जाता है।

⚠️ ध्यान दो: pip install matplotlib.pyplot गलत है ❌
क्योंकि pyplot कोई अलग library नहीं, बल्कि matplotlib का submodule है।
सही तरीका है:
pip install matplotlib
फिर code में import करो:
import matplotlib.pyplot as plt ----->>> next cell me krna hoga


📘 2. import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

🔹 यह line matplotlib library के अंदर से pyplot module को import करती है।
🔹 pyplot में सारे functions होते हैं जैसे —

  • plt.plot() → Line graph

  • plt.bar() → Bar graph

  • plt.pie() → Pie chart

  • plt.show() → Final graph display

🧠 ‘plt’ सिर्फ एक short name (alias) है ताकि बार-बार पूरा नाम न लिखना पड़े।

🧠 "pip install" vs "import" में फर्क क्या है?

🔹 1️⃣ pip install matplotlib

➡️ यह installation command है।
➡️ इसका काम है —
Python में library को system पर download और install करना (जैसे तुम mobile में app install करते हो)।

🧩 Example analogy:
जैसे तुम्हें Instagram use करना है, तो पहले तुम Play Store से install करते हो, तभी phone में आता है।

👉 बिना install किए तुम उसे open नहीं कर सकते।


🔹 2️⃣ import matplotlib.pyplot as plt

➡️ यह import statement है।
➡️ इसका काम है —
Python को यह बताना कि

“अब मैं matplotlib library use करने वाला हूँ।”

यानी library system में install तो हो चुकी है,
अब उसे अपने program में लाना होता है ताकि हम उसके functions (जैसे plt.plot()) use कर सकें।

🧩 Example analogy:
Instagram install तो phone में है,
लेकिन जब तक तुम open नहीं करोगे — use नहीं कर पाओगे।



import matplotlib.pyplot as plt %matplotlib inline plt.plot([1,2,3], [2,7,9]) plt.show()


🧾 Matplotlib Basic Plot Notes 🔹 1️⃣ import matplotlib.pyplot as plt यह command matplotlib library को program में लाता है। pyplot module के अंदर वो सारे functions होते हैं जो graph plotting के लिए use किए जाते हैं। as plt का मतलब है — shortcut name देना, ताकि बार-बार पूरा नाम न लिखना पड़े। 👉 अब हम matplotlib.pyplot.plot() की जगह सिर्फ plt.plot() लिख सकते हैं।

🔹 2️⃣ %matplotlib inline यह line सिर्फ Jupyter Notebook या Google Colab में use की जाती है। इसका काम है — plot को notebook के अंदर ही display करना। अगर ये ना लगाओ, तो कुछ environments में graph दिखेगा नहीं।

🔹 3️⃣ plt.plot([1,2,3], [2,7,9]) यह line graph बनाता है। पहला list [1,2,3] = X-axis values (horizontal axis) दूसरा list [2,7,9] = Y-axis values (vertical axis) यानी (1,2), (2,7), (3,9) points को जोड़कर graph बनाएगा।

🔹 4️⃣ plt.show() यह command final plot को display करता है।


जब तक plt.show() नहीं लिखोगे, plot स्क्रीन पर नहीं दिखाई देगा। ⚙️ Output: 📊 यह एक simple line graph दिखाता है जिसमें X और Y values आपस में जुड़े होते हैं।

🧾 Matplotlib – Basic Chart with Labels and Title 🔹 1️⃣ plt.plot([1,2,3], [2,7,9]) यह command line graph बनाता है। पहला list [1,2,3] = X-axis values दूसरा list [2,7,9] = Y-axis values 👉 यानी graph में तीन points plot होंगे: (1,2), (2,7), (3,9) और इनको जोड़कर एक simple line बनेगी।

🔹 2️⃣ plt.title("Basic chart")

  • यह command graph का title (heading) set करता है।

  • Title से graph का meaning clear होता है कि ये chart क्या दिखा रहा है।
    👉 Output में ऊपर bold letters में “Basic chart” लिखा दिखेगा।


🔹 3️⃣ plt.xlabel('x axis')

  • यह X-axis (horizontal line) को label name देता है।

  • 'x axis' वह text है जो नीचे (horizontal axis) पर दिखेगा।
    👉 इससे पता चलता है कि X-axis किस data को represent कर रही है।


🔹 4️⃣ plt.ylabel('y')

  • यह Y-axis (vertical line) को label name देता है।

  • 'y' वह text है जो बाईं तरफ (vertical axis) पर दिखेगा।
    👉 इससे graph पढ़ना आसान होता है।

    🔹 5️⃣ plt.show() यह command final plot को display करता है। जब तक plt.show() नहीं लगाओगे, graph दिखाई नहीं देगा। ⚙️ Output: 📊 एक simple line graph दिखेगा जिसमें: ऊपर title: “Basic chart”
    नीचे label: “x axis” बाएँ label: “y” और points (1,2), (2,7), (3,9) को जोड़ती हुई line।

🧾 Matplotlib — Multiple Line Graph Explanation

🔹 Code:

x = [20,11,4,12] y = [4,15,19,22] x1 = [2,7,13,17] y1 = [21,25,29,30] plt.plot(x,y) plt.plot(x1,y1) plt.show()

🔹 Step-by-Step Explanation: 1️⃣ x और y पहली line के data हैं x = [20,11,4,12] → X-axis values (पहली line के लिए) y = [4,15,19,22] → Y-axis values (पहली line के लिए) 👉 ये points बनेंगे: (20,4), (11,15), (4,19), (12,22) Matplotlib इन चारों points को आपस में जोड़कर एक पहली line बना देता है। 2️⃣ x1 और y1 दूसरी line के data हैं x1 = [2,7,13,17] → दूसरी line के X-axis values y1 = [21,25,29,30] → दूसरी line के Y-axis values 👉 ये points बनेंगे: (2,21), (7,25), (13,29), (17,30) इन points को जोड़कर Matplotlib एक दूसरी line बनाएगा। 3️⃣ plt.plot(x,y) यह पहली line draw करेगा। X = 20,11,4,12 Y = 4,15,19,22 By default यह एक blue color line बनाता है। 4️⃣ plt.plot(x1,y1) यह दूसरी line draw करेगा। X1 = 2,7,13,17 Y1 = 21,25,29,30 By default यह एक orange color line बनाता है। 5️⃣ plt.show() यह दोनों lines को same graph में एक साथ display करता है। ⚙️ Output Visualization (Imagine Chart Like This):



🧾 Seaborn — Installation and Basics


🔹 1️⃣ Installation Command

pip install seaborn

🔸 Explanation:

  • यह command Python में Seaborn library install करने के लिए होती है।

  • pip = Python का package manager (software installer)।

  • seaborn = एक data visualization library, जो matplotlib के ऊपर बनी है


🔹 2️⃣ Import Command

import seaborn as sns

🔸 Explanation:

  • इससे Seaborn library को Python program में use किया जा सकता है।

  • as sns का मतलब है shortcut name देना (ताकि हर बार पूरा नाम न लिखना पड़े)।


🔹 3️⃣ Purpose of Seaborn

Seaborn का use data को graphically visualize करने के लिए किया जाता है।
यह graphs को ज़्यादा सुंदर और readable बनाता है।

📊 Example types of graphs:

  • Bar Plot → श्रेणीवार comparison दिखाने के लिए

  • Count Plot → किसी category की frequency दिखाने के लिए

  • Line Plot → trend दिखाने के लिए

  • Box Plot → data distribution और outliers देखने के लिए

  • Heatmap → correlation और pattern देखने के लिए


🔹 4️⃣ Why Use Seaborn?

FeatureMatplotlibSeaborn
Graph LookSimpleStylish & Colored
Syntaxथोड़ा लंबाआसान और Short
Built-in Stylesकमज़्यादा (themes, colors)
Statistical PlotsManualBuilt-in support
#Example: Scatter plot # Step 1: Define data first x = [1,2,3,4,5] y = [2,4,6,8,10] # Step 2: Then create plot sns.scatterplot(x=x, y=y) plt.xlabel('x axis') plt.ylabel('y axis') plt.title('Scatter plot') plt.show()


🧾 Seaborn — Scatter Plot (with Explanation Notes)


🔹 1️⃣ Step 1: Define Data First

x = [1,2,3,4,5] y = [2,4,6,8,10]
  • यह दो lists हैं:

    • x = X-axis values

    • y = Y-axis values

  • यहाँ y = 2x का relation है — यानी linear relationship।

  • ये points represent करेंगे:
    (1,2), (2,4), (3,6), (4,8), (5,10)

📌 मतलब: जैसे-जैसे x बढ़ेगा, y भी दुगुना बढ़ेगा।


🔹 2️⃣ Step 2: Create Scatter Plot

sns.scatterplot(x=x, y=y)
  • यह Seaborn का scatterplot function है।

  • इसका काम: हर (x, y) जोड़े को graph पर एक dot (●) के रूप में दिखाना।

  • Example में:
    (1,2), (2,4), (3,6), (4,8), (5,10) ये पाँच dots बनेंगे।

  • क्योंकि y = 2x, सारे dots एक सीधी diagonal line पर होंगे।

📊 Scatter plot data में relation दिखाने के लिए use किया जाता है
(जैसे — positive, negative या no relationship)।


🔹 3️⃣ Label & Title Add Karna

plt.xlabel('x axis') plt.ylabel('y axis') plt.title('Scatter plot')
  • plt.xlabel() → X-axis का नाम set करता है

  • plt.ylabel() → Y-axis का नाम set करता है

  • plt.title() → Graph के ऊपर title देता है
    👉 ताकि chart clear और readable लगे।


🔹 4️⃣ Display Final Graph

plt.show()
  • यह command final chart को display करता है।

  • बिना plt.show() के कुछ IDEs में graph दिखाई नहीं देता।


⚙️ Output Visualization:

📈 Graph में पाँच dots दिखेंगे —
जो straight upward line में होंगे क्योंकि y हर बार x का double है।

Comments

Popular posts from this blog

Python Final Lectures

 Q- how to Print Hello World print("Hello World") Variables in python ------- age = 30   #variable should be intutive so that we can learn any time print(age) Note: Shift+Enter is shortcut to run command 2) ' #' this is for writing the comment in python Rules for Variables--- Variable can not be start with any number like - 1age  Number can use in between and end with variable like - age1 age2 Special characters are not allowed expect _ (underscore) like - age_my Space not allowed in variable  Python is case sensitive  Way to define Variable --- age1,age2 = 30,25  age1 = 30 age2 = 25 age1=age2=30   #if 30 age for both variable   >> Data type the type of data is basically data type Integer = age1 to age3 is basically integer   , Integer is basically full number lets check = type(age1)  #it will give u print int float=  basically decimal values Interest =  30.24 type(Interest) #answer is float Message = ...

Add CSS using external CSS

>>> U just need to create a another page and save it with the name style.css >>> and then go to link that style page with your html docs how to link your css with html page ? >>> You can find code below , it will help you to link your external page with your html docs <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Divyanshu Khare || MERN Developer</title> <meta description = "description" content="Divyanshu Khare's website"> <link rel="stylesheet" type="text/css" href="style.css">   <!----------link external css page ---------> </head> <body> </body> </html>

Python

Indexing--  it will help u to fetch single character  string= "Python" string[2] # slicing process of fetching a sub-string from the given string  #sequence of charater we can fetch means more than 1 character string="Divyanshu" string[2:4+1]   #basically here number is index value #string[start_index:end+index+1] string = "Hunny"   #indexing agr positive hai to left se count hoga #right se negative me string[:]  #it will give u entire string #now If i want to any characterwise index like string is Hunny and I want un only #string[start_index:end_index+1:step] string[1:4:2] #reverse your string #string[:: -1] string="Baba hunny" string[:: -1] # to convert into lowecase string="New Divyanshu" new_string=string.lower()  #new_string becase we've to create another string print(new_string) s1={1,2,3,4,5}    s2={3,2,8,67,85} s3=s1.union(s2) s3   #isme add hota hai whole value lekin common value update nhi hongi #intersection - ...