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 sheet. शांत checks. समजलं का?

थोडक्यात उत्तर

उभा load path:

  1. shop_sales.csv project folder मध्ये ठेवा.
  2. df = pd.read_csv("shop_sales.csv")
  3. df.head() आणि df.shape
  4. Excel: pip install openpyxl मग pd.read_excel("client_hours.xlsx")
  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: files फक्त disk वर. After: memory मध्ये tables, sales sum 190.

काळजीपूर्वक का वाचायचं?

  1. चुकीचा delimiter → सगळे columns एक झाले.
  2. चुकीचा header → numbers column names बनले.
  3. चुकीची Excel sheet → रिकामी tab silently.

Cleaning चुकीच्या load ला दुरुस्त करत नाही.

read_csv — shop sales

city,channel,sales
Mumbai,Online,120
Pune,Online,70
import pandas as pd
df = pd.read_csv("shop_sales.csv")
print(df.head())
print(df["sales"].sum())  # 190

उपयुक्त knobs: sep=";", encoding="utf-8" / "latin-1", header=0, nrows=100, usecols=["city", "sales"].

read_excel — Infosys-style client sheet

client hours
A 100
B 90
xlsx = pd.read_excel("client_hours.xlsx", sheet_name="hours")
print(xlsx["hours"].sum())  # 190

Notes: अनेक .xlsx साठी openpyxl; sheet_name=0 = पहिली sheet; title rows वर skiprows लागेल.

Netflix-style watches (नंतर clean)

title,watches
Show A,100
Show B,
Show C,90

read_csv succeed होतो; रिकामी watches → NaN; पुढची cleaning guide fillna/dropna करते.

Common errors

Symptom Cause Fix
FileNotFoundError चुकीची folder os.getcwd(); path ठीक करा
एकच विशाल column Wrong sep sep=";"
Unnamed: 0 Extra index index_col=0 किंवा drop
Excel empty Wrong sheet sheet_name द्या

Ravindra Bagale's Tip

प्रत्येक load नंतर shape, columns.tolist(), आणि एक sum. तीन ओळी. एक तास खोटं debugging वाचवतात. समजलं का?

Practice task

  1. दोन-row shop CSV save → total 190.
  2. read_csv ने sum सिद्ध.
  3. तेच Excel मध्ये → read_excel. 4.Delimiter मुद्दाम मोडून sep ने ठीक करा.

समजलं का? 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.