Real projects me data CSV, Excel ya database se aata hai. Is lesson me hum ek chhota sales dataset load karenge aur usko explore karne ke standard steps seekhenge. Yahi steps aap har naye dataset pe karenge.
CSV load karna
Normally aap pd.read_csv("sales.csv") likhenge. Yaha example ko self-contained rakhne ke liye CSV text ko StringIO se padh rahe hain — result bilkul same hai:
Example
from io import StringIO
import pandas as pd
csv_data = """order_id,date,city,category,product,quantity,price
1001,2026-01-05,Delhi,Electronics,Headphones,2,1500
1002,2026-01-06,Mumbai,Clothing,T-Shirt,3,499
1003,2026-01-06,Delhi,Clothing,Jeans,1,1299
1004,2026-01-07,Bangalore,Electronics,Mouse,4,650
1005,2026-01-08,Mumbai,Grocery,Rice 5kg,2,420
1006,2026-01-09,Pune,Electronics,Keyboard,1,
1007,2026-01-10,Delhi,Grocery,Tea 1kg,5,380
1008,2026-01-11,Bangalore,Clothing,Jacket,1,2499
1009,2026-01-12,Pune,Grocery,Oil 1L,3,160
1010,2026-01-12,Mumbai,Electronics,Charger,2,899"""
df = pd.read_csv(StringIO(csv_data), parse_dates=["date"])
parse_dates=["date"] se date column text ki jagah asli date type ban jaata hai.
head() aur tail()
Example
print(df.head()) # pehli 5 rows
print()
print(df.tail(3)) # aakhri 3 rows
Output
order_id date city category product quantity price
0 1001 2026-01-05 Delhi Electronics Headphones 2 1500.0
1 1002 2026-01-06 Mumbai Clothing T-Shirt 3 499.0
2 1003 2026-01-06 Delhi Clothing Jeans 1 1299.0
3 1004 2026-01-07 Bangalore Electronics Mouse 4 650.0
4 1005 2026-01-08 Mumbai Grocery Rice 5kg 2 420.0
order_id date city category product quantity price
7 1008 2026-01-11 Bangalore Clothing Jacket 1 2499.0
8 1009 2026-01-12 Pune Grocery Oil 1L 3 160.0
9 1010 2026-01-12 Mumbai Electronics Charger 2 899.0
shape aur info()
info() ek hi baar me columns, unke types aur non-null count dikha deta hai. Missing values pakadne ka ye sabse fast tareeka hai:
Example
print(df.shape)
print()
df.info()
Output
(10, 7)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10 entries, 0 to 9
Data columns (total 7 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 order_id 10 non-null int64
1 date 10 non-null datetime64[ns]
2 city 10 non-null object
3 category 10 non-null object
4 product 10 non-null object
5 quantity 10 non-null int64
6 price 9 non-null float64
dtypes: datetime64[ns](1), float64(1), int64(2), object(3)
memory usage: 692.0+ bytes
Dhyan dijiye — price me 10 me se sirf 9 non-null values hain. Yaani ek value missing hai. Isko hum cleaning wale lesson me theek karenge.
describe() — numbers ka summary
Example
print(df[["quantity", "price"]].describe())
Output
quantity price
count 10.000000 9.000000
mean 2.400000 922.888889
std 1.349897 736.799573
min 1.000000 160.000000
25% 1.250000 420.000000
50% 2.000000 650.000000
75% 3.000000 1299.000000
max 5.000000 2499.000000
Ek line me count, mean, standard deviation, min, max aur percentiles mil gaye. 50% wali row median hai.
Categories explore karna
Example
print(df["city"].value_counts())
print()
print("Categories:", df["category"].unique())
print("Kitne products:", df["product"].nunique())
Output
city
Delhi 3
Mumbai 3
Bangalore 2
Pune 2
Name: count, dtype: int64
Categories: ['Electronics' 'Clothing' 'Grocery']
Kitne products: 10
Missing values aur sorting
Example
print(df.isnull().sum())
print()
print(df.sort_values("price", ascending=False).head(3))
Output
order_id 0
date 0
city 0
category 0
product 0
quantity 0
price 1
dtype: int64
order_id date city category product quantity price
7 1008 2026-01-11 Bangalore Clothing Jacket 1 2499.0
0 1001 2026-01-05 Delhi Electronics Headphones 2 1500.0
2 1003 2026-01-06 Delhi Clothing Jeans 1 1299.0
Doosre formats
Source | Padhna | Likhna |
|---|---|---|
CSV |
|
|
Excel |
|
|
SQL database |
|
|
JSON |
|
|
Naya dataset milte hi ye 5 commands chalaiye:
head(),shape,info(),describe(),isnull().sum(). Paanch minute me aapko dataset ki poori tasveer mil jaayegi.