pandas से CSV और Excel कैसे पढ़ें
Read this guide in: English · मराठी · हिंदी
pd.read_csv text table load करता है। pd.read_excel .xlsx से sheet। फिर head() और shape साबित करते हैं कि file आई। Shop example total 190 — file सही हो तो।
दोस्तों! File disk पर बैठती है जब तक pandas न पढ़े। आज CSV और Excel — shop sales और Infosys-style hours। शांत checks। समझा?
संक्षिप्त उत्तर
खड़ा load path:
shop_sales.csvproject folder में रखो।df = pd.read_csv("shop_sales.csv")df.head()औरdf.shape- Excel:
openpyxlफिरpd.read_excel(...) - गलत preview हो तो sep / header / sheet_name ठीक करो।
- Known total confirm (190)।
file on disk → read_csv/read_excel → head → shape → trust
Language: English · मराठी · हिंदी
इस guide से पहले क्या चाहिए?
- काम करता Jupyter + pandas।
- अपनी sample CSV।
- Course: read CSV and Excel.
Before और after
Before — CSV / Excel still only on disk.
After — read_csv / read_excel; sum 190.
Before: सिर्फ़ disk। After: memory में tables, sum 190.
सावधानी से क्यों पढ़ें?
- गलत delimiter → सब columns एक।
- गलत header → numbers = column names।
- गलत Excel sheet → खाली tab।
read_csv — shop sales
import pandas as pd
df = pd.read_csv("shop_sales.csv")
print(df["sales"].sum()) # 190
Knobs: sep=";", encoding, header, nrows, usecols.
read_excel — Infosys-style
xlsx = pd.read_excel("client_hours.xlsx", sheet_name="hours")
print(xlsx["hours"].sum()) # 190
openpyxl ज़रूरी हो सकता है। sheet_name=0 = पहली sheet।
Netflix-style watches
खाली watches → NaN। Load पहले, clean बाद में।
Common errors
| Symptom | Fix |
|---|---|
| FileNotFoundError | path / folder |
| एक विशाल column | sep=";" |
| Unnamed: 0 | index_col=0 |
| Excel empty | सही sheet_name |
Ravindra Bagale's Tip
हर load के बाद shape, columns, एक sum। तीन लाइनें। घंटों का नकली debug बचाती हैं। समझा?
Practice task
- दो-row CSV total 190.
- read_csv से sum सिद्ध।
- Excel में वही → read_excel।
- Delimiter तोड़कर
sepसे ठीक करो।
Samajla ka? read_csv और read_excel files को DataFrames में लाते हैं। head + sum = trust। फिर filter। अब आगे चलें।
Frequently asked questions
Do I need openpyxl?
Yes for many modern .xlsx files with read_excel.
Unicode / encoding errors on CSV?
Try encoding="utf-8" or encoding="latin-1" after you confirm the file source.
My header is wrong
Use header=0 (default) or header=1 if titles sit above the real columns; skiprows can help.
Semicolon CSV from Excel?
sep=";" if commas are not the delimiter.
Large files?
Start with nrows=100 while exploring; full load later.
Course lesson?
read_csv and Excel in the pandas chapter — linked below.