Ravindra BagaleCourses & study guides Track your progress

Guides

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:

  1. shop_sales.csv project folder में रखो।
  2. df = pd.read_csv("shop_sales.csv")
  3. df.head() और df.shape
  4. Excel: openpyxl फिर pd.read_excel(...)
  5. गलत preview हो तो sep / header / sheet_name ठीक करो।
  6. 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 read_csv CSV and Excel still on disk.

Before — CSV / Excel still only on disk.

After read_csv Both files loaded; sum 190.

After — read_csv / read_excel; sum 190.

Before: सिर्फ़ disk। After: memory में tables, sum 190.

सावधानी से क्यों पढ़ें?

  1. गलत delimiter → सब columns एक।
  2. गलत header → numbers = column names।
  3. गलत 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

  1. दो-row CSV total 190.
  2. read_csv से sum सिद्ध।
  3. Excel में वही → read_excel।
  4. 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.