Printing is unavailable

This course is licensed for personal online viewing only.

Public preview • CL-P000000-C33-L1292-F4562EE0

Home Dashboard
Chapter 1 · Module 1 — Pandas Fundamentals

Introduction to Pandas

Priority
  • JobHigh
  • InterviewMedium
  • DevelopmentHigh
3,723
words
21
min read
2
tools

1. Learning Outcomes#

या chapter नंतर तुम्हाला:

  • Pandas म्हणजे काय आणि Data Science मध्ये त्याची गरज का पडते हे समजेल.
  • tabular data म्हणजे काय हे स्पष्टपणे समजेल.
  • row, column, label आणि index यांची basic भूमिका समजेल.
  • Series आणि DataFrame यांच्यातील high-level फरक समजेल.
  • import pandas as pd का वापरले जाते हे समजेल.
  • Pandas मधील basic data analysis workflow समजेल.
  • Pandas label-based data handling कसे करते याची basic कल्पना येईल.
  • automatic data alignment म्हणजे काय याची high-level awareness मिळेल.
  • कोणत्या प्रकारच्या data-analysis कामांसाठी Pandas उपयोगी आहे हे ओळखता येईल.

2. Pandas ची गरज#

Data Science मध्ये आपल्याला अनेकदा records च्या स्वरूपात data मिळतो.

उदाहरणार्थ, एका दुकानाकडे असा sales data असू शकतो:

Customer City Orders Amount
Asha Pune 3 2400
Ravi Mumbai 2 1800
Neha Pune 5 4200

आपल्याला या data मधून अनेक कामे करावी लागू शकतात.

उदाहरणार्थ:

  • फक्त Pune चे records पाहणे
  • Amount column तपासणे
  • missing values शोधणे
  • चुकीचा data clean करणे
  • काही rows निवडणे
  • total किंवा average काढणे
  • data नवीन format मध्ये export करणे

Python मध्ये ही सर्व कामे manually करता येतात.

पण data मोठा झाला की plain lists, dictionaries आणि loops वापरून प्रत्येक operation manually करणे अवघड होऊ शकते.

इथे Pandas आपले काम सोपे करते.

Key Idea

Pandas आपल्याला structured data समजून घेण्यासाठी, select करण्यासाठी, clean करण्यासाठी, transform करण्यासाठी आणि analyze करण्यासाठी सोयीची tools देते.

3. What is Pandas?#

Pandas ही Python मधील data manipulation आणि data analysis साठी वापरली जाणारी library आहे.

सोप्या भाषेत सांगायचे तर:

data सोबत व्यवस्थित काम करण्यासाठी Pandas आपल्याला तयार structures आणि operations देते.

विशेषतः rows आणि columns मध्ये असलेल्या data सोबत Pandas खूप उपयोगी ठरते.

उदाहरणार्थ:

  • CSV मधील records
  • Excel मधील table
  • database मधून मिळालेला result
  • sales records
  • employee data
  • student marks
  • transaction records
  • sensor observations

Pandas शिकताना सुरुवातीला दोन मुख्य structures वारंवार दिसतात:

  • Series
  • DataFrame

त्यांचा high-level अर्थ आपण या chapter मध्ये समजून घेणार आहोत.

4. Why Pandas is Used in Data Science#

Data Science मध्ये फक्त model तयार करणे महत्त्वाचे नसते.

त्याआधी data usable असणे आवश्यक असते.

Real-world data मध्ये अनेक समस्या असू शकतात:

  • काही values missing असतात.
  • काही records duplicate असतात.
  • unnecessary columns असू शकतात.
  • column values चुकीच्या format मध्ये असू शकतात.
  • आपल्याला पूर्ण dataset ऐवजी specific data पाहायचा असतो.
  • analysis साठी data transform करावा लागू शकतो.

Pandas अशा कामांसाठी practical interface देते.

एक सामान्य data-analysis flow असा दिसू शकतो:

Visual Diagram80%

Rendering diagram…

हा flow लक्षात ठेवणे महत्त्वाचे आहे.

Pandas म्हणजे फक्त data उघडण्यासाठीची library नाही.

ती पूर्ण data-processing workflow चा महत्त्वाचा भाग बनू शकते.

5. Understanding Tabular Data#

Pandas समजण्याआधी tabular data समजणे आवश्यक आहे.

Tabular data म्हणजे rows आणि columns मध्ये organize केलेला data.

आपण Excel sheet किंवा database table पाहिली असेल तर ही कल्पना ओळखीची वाटेल.

खाली एक छोटा dataset पाहा:

Figure 1: Simple tabular dataset with rows and columns
Simple tabular dataset with rows and columnsIndex012NameAshaRaviNehaCityPuneMumbaiPuneSales240018004200

या table मध्ये प्रत्येक भागाची वेगळी भूमिका आहे.

Row#

एका row मध्ये सामान्यतः एका record ची माहिती असते.

उदाहरणार्थ:

Asha | Pune | 2400

हा एक record आहे.

त्यामध्ये एका customer शी संबंधित values आहेत.

Column#

Column म्हणजे एका प्रकारची information.

वरील उदाहरणात:

  • Name → customer चे नाव
  • City → customer चे शहर
  • Sales → sales amount

म्हणजे प्रत्येक column चा एक specific meaning असतो.

Label#

Name, City, Sales ही column labels आहेत.

Label म्हणजे data च्या एखाद्या भागाला दिलेले ओळखण्याजोगे नाव.

Pandas मध्ये labels फार महत्त्वाचे आहेत.

कारण आपण अनेक operations मध्ये position पेक्षा label वापरून data identify करू शकतो.

उदाहरणार्थ, Sales हा शब्द पाहिल्यावर त्या column मध्ये काय आहे हे लगेच समजते.

फक्त "third column" असे म्हणण्यापेक्षा Sales हे label अधिक स्पष्ट आहे.

Index#

Pandas मध्ये rows साठीही labels असू शकतात.

या row labels च्या collection ला साधारणपणे index म्हणतो.

वरील dataset मध्ये:

  • पहिल्या row चा index → 0
  • दुसऱ्या row चा index → 1
  • तिसऱ्या row चा index → 2

Default index अनेकदा 0, 1, 2, ... असा दिसतो.

पण index नेहमी number असायलाच हवा असे नाही.

तो meaningful labels वरही आधारित असू शकतो.

Remember

Column label column ओळखण्यास मदत करते, तर index row ओळखण्यास मदत करतो.

6. Pandas in the Python Data Science Ecosystem#

Pandas एकट्याने संपूर्ण Data Science ecosystem तयार करत नाही.

Python data ecosystem मध्ये वेगवेगळ्या libraries वेगवेगळी कामे करतात.

High-level picture अशी आहे:

Visual Diagram80%

Rendering diagram…

इथे महत्त्वाची गोष्ट म्हणजे प्रत्येक library ची भूमिका वेगळी असू शकते.

Pandas ची मुख्य ताकद structured आणि labeled data सोबत काम करण्यात आहे.

NumPy सारख्या libraries numerical computing मध्ये महत्त्वाच्या असतात.

Visualization libraries data graphically दाखवतात.

Machine Learning libraries models तयार करण्यात वापरल्या जातात.

या chapter साठी एवढे लक्षात ठेवा:

Key Idea

Pandas हा Python Data Science workflow मधील data preparation आणि analysis चा महत्त्वाचा भाग आहे.

7. Understanding Series — High-Level Overview#

Series हा Pandas मधील एक मुख्य data structure आहे.

High-level level वर:

Series म्हणजे labels असलेली one-dimensional collection of values.

उदाहरण म्हणून एका दुकानाची तीन दिवसांची sales कल्पना करा:

Day Sales
Monday 1200
Tuesday 1500
Wednesday 1800

इथे values एकाच मुख्य data sequence मध्ये आहेत:

1200, 1500, 1800

आणि प्रत्येक value सोबत एक label आहे:

Monday, Tuesday, Wednesday

ही कल्पना Series समजण्यासाठी उपयोगी आहे.

महत्त्वाचे

Series ला फक्त "Python list" समजू नका. Series मध्ये values सोबत labels/index ची कल्पना महत्त्वाची असते.

8. Understanding DataFrame — High-Level Overview#

DataFrame हा Pandas मधील सर्वात जास्त दिसणाऱ्या structures पैकी एक आहे.

High-level level वर:

DataFrame म्हणजे rows आणि columns मध्ये organize केलेली labeled two-dimensional data structure.

उदाहरण:

Name City Sales
Asha Pune 2400
Ravi Mumbai 1800
Neha Pune 4200

इथे:

  • अनेक rows आहेत.
  • अनेक columns आहेत.
  • प्रत्येक column ला label आहे.
  • प्रत्येक row ला index असू शकतो.

म्हणून DataFrame पाहताना spreadsheet किंवा database table सारखी mental picture ठेवणे सुरुवातीला उपयोगी ठरते.

पण DataFrame फक्त दिसायला table सारखा नाही.

Pandas त्या table वर programmatically operations करण्याची क्षमता देते.

9. Series आणि DataFrame एकत्र समजून घेऊ#

खाली visual comparison पाहा:

Figure 2: High-level comparison of a Series and a DataFrame
High-level comparison of a Series and a DataFrameSeries — one main valuecolumn with labelsSeries — one main value column with labelsIndexMonTueWedSales120015001800DataFrame — multiplelabeled columnsDataFrame — multiple labeled columnsIndex012NameAshaRaviNehaSales240018004200

Series मध्ये आपण एक labeled sequence पाहत आहोत.

DataFrame मध्ये multiple columns असलेली table-like structure पाहत आहोत.

Series vs DataFrame#

Point Series DataFrame
Basic shape One-dimensional Two-dimensional
Main idea Labeled sequence of values Labeled table
Columns मुख्यतः एक value sequence Multiple columns असू शकतात
Row labels Index असतो Index असतो
Typical mental model एक labeled column पूर्ण table
Common Mistake

DataFrame म्हणजे "अनेक Python lists एकत्र" एवढाच अर्थ घेऊ नका. Pandas मध्ये labels, index आणि table-oriented operations यामुळे त्याला वेगळी behavior मिळते.

10. Importing Pandas#

Python program मध्ये Pandas वापरण्याआधी library import करावी लागते.

सामान्य convention अशी आहे:

PYTHON
import pandas as pd

या statement चे भाग समजून घेऊ.

import pandas म्हणजे Python program मध्ये Pandas library उपलब्ध करून घेणे.

as pd म्हणजे pandas या नावासाठी pd हा short alias वापरणे.

त्यामुळे पुढे वारंवार पूर्ण pandas लिहिण्याऐवजी आपण pd वापरू शकतो.

उदाहरणार्थ, Pandas मधील DataFrame नाव वापरताना सामान्यतः pd.DataFrame असा reference दिसतो.

इथे pd ही नवीन library नाही.

ती फक्त pandas साठी वापरलेली conventional short name आहे.

Remember

pd हा Pandas चा official वेगळा component नाही. तो import pandas as pd मध्ये तयार केलेला alias आहे.

11. Basic Pandas Data Analysis Workflow#

Pandas शिकताना individual methods पेक्षा आधी मोठा workflow समजून घेणे उपयोगी ठरते.

सामान्यतः data सोबत काम करताना खालील stages दिसतात.

1. Load Data#

सर्वप्रथम data program मध्ये आणावा लागतो.

Data कुठूनही येऊ शकतो.

उदाहरणार्थ:

  • CSV file
  • spreadsheet
  • database
  • application-generated dataset

या stage चे मुख्य उद्दिष्ट आहे:

analysis करायचा data Pandas मध्ये उपलब्ध करणे.

2. Inspect Data#

Data load झाल्यानंतर लगेच analysis सुरू करणे योग्य नसते.

सुरुवातीला data समजून घ्यावा लागतो.

आपल्याला basic गोष्टी तपासायच्या असतात:

  • कोणते columns आहेत
  • किती records आहेत
  • values साधारण कशा दिसतात
  • काही obvious problems दिसतात का

याला data inspection म्हणता येईल.

यामुळे पुढचा निर्णय अंदाजाने न घेता actual data पाहून घेता येतो.

3. Select Required Data#

बहुतेक वेळा पूर्ण dataset प्रत्येक calculation साठी आवश्यक नसतो.

उदाहरणार्थ, table मध्ये दहा columns असतील पण analysis साठी फक्त:

  • City
  • Sales

हे दोन columns आवश्यक असू शकतात.

किंवा सर्व customers ऐवजी फक्त Pune चे records आवश्यक असू शकतात.

म्हणून required data निवडणे हा महत्त्वाचा stage आहे.

4. Clean and Transform Data#

Real-world data नेहमी ready-to-use नसतो.

आपल्याला data clean किंवा transform करावा लागू शकतो.

High-level examples:

  • missing values handle करणे
  • duplicate records तपासणे
  • चुकीचे formats सुधारण्याची गरज ओळखणे
  • values analysis साठी योग्य रूपात बदलणे

या chapter मध्ये specific cleaning methods शिकत नाही आहोत.

इथे फक्त workflow मधील त्यांची भूमिका समजून घेत आहोत.

5. Analyze Data#

Data usable झाल्यानंतर analysis करता येतो.

उदाहरणार्थ:

  • total sales
  • average sales
  • category-wise comparison
  • group-level summaries
  • trends

Pandas अशा analysis साठी अनेक capabilities देते.

6. Export Results#

Analysis पूर्ण झाल्यानंतर result पुढे वापरण्यासाठी save किंवा export करावा लागू शकतो.

उदाहरणार्थ:

  • दुसऱ्या file मध्ये
  • reporting workflow मध्ये
  • पुढील analysis stage साठी

म्हणून Pandas workflow फक्त "data read करणे" येथे संपत नाही.

Visual Diagram80%

Rendering diagram…

Key Idea

चांगला analysis हा थेट calculation पासून सुरू होत नाही. आधी data load, understand, select आणि prepare करणे आवश्यक असते.

12. Label-Based Data Handling#

Pandas समजण्यासाठी labels ची कल्पना फार महत्त्वाची आहे.

Traditional positional thinking मध्ये आपण असे विचारू शकतो:

"मला दुसरा column हवा आहे."

Label-based thinking मध्ये आपण म्हणतो:

"मला Sales column हवा आहे."

दुसरी पद्धत अधिक meaningful असते.

कारण Sales हे नाव त्या data चा अर्थ सांगते.

त्याचप्रमाणे rows ना meaningful index labels असतील तर row ची position लक्षात ठेवण्याऐवजी label वापरता येतो.

यामुळे code अनेकदा अधिक readable होतो.

उदाहरणार्थ, मनात असा dataset ठेवा:

Product Quantity Price
Keyboard 2 900
Mouse 3 500

Price हा label पाहताच त्या column मधील values चा अर्थ समजतो.

ही label-awareness Pandas च्या design मधील महत्त्वाची कल्पना आहे.

13. Automatic Data Alignment — High-Level Awareness#

Pandas मध्ये labels फक्त data ओळखण्यासाठी नसतात.

काही operations मध्ये Pandas labels लक्षात घेऊन data align करू शकते.

हा concept सुरुवातीला थोडा वेगळा वाटू शकतो.

दोन labeled value sets पाहा.

पहिल्या set मध्ये:

Label Value A
Mon 10
Tue 20

दुसऱ्या set मध्ये order उलटा आहे:

Label Value B
Tue 2
Mon 1

फक्त physical position पाहिली तर:

  • first value 10 आणि first value 2
  • second value 20 आणि second value 1

अशी pairing करण्याचा मोह होऊ शकतो.

पण Pandas labeled data सोबत काम करताना corresponding labels match करण्याची क्षमता वापरू शकते.

Visual पाहा:

Figure 3: High-level idea of automatic alignment by labels
High-level idea of automatic alignment by labelsFirst labeled dataFirst labeled dataLabelMonTueA1020Second labeled dataSecond labeled dataLabelTueMonB21Matched by labelMatched by labelLabelMonTueMatched Values10 and 120 and 2

इथे order वेगळा असला तरी Mon ला Mon सोबत आणि Tue ला Tue सोबत relate करता येते.

यालाच high-level level वर automatic alignment ची कल्पना म्हणता येते.

महत्त्वाचे

Pandas मध्ये labels हे फक्त display names नाहीत. काही operations च्या behavior मध्येही त्यांची भूमिका असू शकते.

जर labels match होत नसतील तर result मध्ये missing-data related situation तयार होऊ शकते.

त्या behavior चे detailed handling पुढील practical operations शिकताना अधिक स्पष्ट होईल.

14. Pandas कधी वापरायचे#

Pandas विशेषतः structured data सोबत काम करताना उपयोगी आहे.

उदाहरणार्थ:

  • rows आणि columns असलेला dataset
  • CSV-based analysis
  • business records
  • sales data
  • customer data
  • employee data
  • experiment observations
  • reporting साठी तयार करायचा data
  • cleaning आणि transformation लागणारा dataset

Pandas ची गरज प्रत्येक Python program मध्ये नसते.

उदाहरणार्थ, अगदी छोट्या calculation साठी किंवा साध्या program logic साठी Pandas वापरणे आवश्यक नाही.

योग्य mental model असा आहे:

Key Idea

Structured, labeled data वर systematic analysis करायचा असेल तर Pandas हा Python मधील अत्यंत उपयोगी पर्याय आहे.

15. छोटा Mental Model#

Pandas शिकताना खालील picture मनात ठेवा:

Visual Diagram80%

Rendering diagram…

इथे Series आणि DataFrame ही data structures आहेत.

आणि Pandas आपल्याला या structures वर useful data operations करण्याची क्षमता देते.

16. Common Beginner Confusions#

Pandas म्हणजे database नाही#

Pandas database server नाही.

ती Python library आहे.

Database मध्ये data persistently store केला जाऊ शकतो.

Pandas program मध्ये data load करून त्यावर analysis आणि manipulation करण्यासाठी वापरली जाऊ शकते.

DataFrame म्हणजे Excel file नाही#

DataFrame table सारखा दिसू शकतो.

पण तो Excel file स्वतः नाही.

तो Python program मध्ये वापरता येणारा Pandas data structure आहे.

Index म्हणजे फक्त row number नाही#

Default index अनेकदा 0, 1, 2... असा दिसतो.

त्यामुळे सुरुवातीला index म्हणजे row number असे वाटू शकते.

पण index चा मुख्य अर्थ row labels असा आहे.

pd म्हणजे वेगळी library नाही#

pd हे फक्त pandas साठी alias आहे.

PYTHON
import pandas as pd

या statement मुळे ते नाव उपलब्ध होते.

17. स्वतःची समज तपासा#

Tabular data मध्ये row आणि column यांची basic भूमिका काय असते?Show Answer

Row सामान्यतः एका record चे representation करते.

Column एका specific प्रकारची information किंवा attribute represent करते.

उदाहरणार्थ employee table मध्ये एक row एका employee ची असू शकते, तर Name, Department, Salary हे वेगवेगळे columns असू शकतात.


Series आणि DataFrame मधील high-level फरक काय आहे?Show Answer

Series ही one-dimensional labeled data structure आहे.

DataFrame ही rows आणि multiple columns असलेली two-dimensional labeled data structure आहे.


Pandas मध्ये labels महत्त्वाचे का आहेत?Show Answer

Labels मुळे data चा अर्थ स्पष्टपणे identify करता येतो.

Pandas label-based selection आणि alignment सारख्या behavior मध्येही labels वापरू शकते.

18. Interview Preparation#

What is Pandas in Python?Show Answer

Pandas is a Python library used for data manipulation and data analysis. It provides labeled data structures such as Series and DataFrame that make working with structured and tabular data convenient.

Key Points:

  • Python library
  • Data manipulation
  • Data analysis
  • Series and DataFrame
  • Structured and labeled data

Why interviewer asks this:

The interviewer wants to verify that you understand the basic purpose of Pandas rather than only knowing its syntax.


What is the difference between a Series and a DataFrame?Show Answer

A Series is a one-dimensional labeled data structure, while a DataFrame is a two-dimensional labeled data structure organized into rows and columns.

Key Points:

  • Series → one-dimensional
  • DataFrame → two-dimensional
  • Both support labels/index concepts

Why interviewer asks this:

Series and DataFrame are fundamental Pandas structures, so this checks whether the candidate has a correct conceptual foundation.


Why is Pandas commonly imported as pd?Show Answer

pd is the conventional alias used for the Pandas library. It makes Pandas references shorter and keeps Python code consistent with common community conventions.

Key Points:

  • pd is an alias
  • It is created using import pandas as pd
  • It is not a separate library

Why interviewer asks this:

The interviewer is checking whether the candidate understands basic Pandas setup and common Python conventions.

19. Chapter Recap#

या chapter मधून खालील गोष्टी पक्क्या लक्षात ठेवा:

  • Pandas ही Python मधील data manipulation आणि analysis library आहे.
  • structured आणि tabular data सोबत काम करताना Pandas विशेषतः उपयोगी आहे.
  • tabular data मध्ये rows आणि columns असतात.
  • column label column चा अर्थ सांगते.
  • index rows identify करण्यासाठी वापरला जातो.
  • Series ही high-level level वर one-dimensional labeled structure आहे.
  • DataFrame ही two-dimensional labeled table-like structure आहे.
  • Pandas सामान्यतः import pandas as pd ने import केली जाते.
  • common workflow म्हणजे Load → Inspect → Select → Clean/Transform → Analyze → Export.
  • Pandas मध्ये labels data handling चा महत्त्वाचा भाग आहेत.
  • automatic alignment मुळे corresponding labels च्या आधारावर data relate होऊ शकतो.
Summary

Pandas शिकण्याची खरी सुरुवात methods पाठ करण्यापासून होत नाही. DataFrame, Series, rows, columns, index आणि labels यांची mental picture स्पष्ट झाली की पुढील Pandas operations समजणे खूप सोपे होते.

Interactive learning

Practice lab

Apply this chapter with guided activities, immediate feedback, explanations, and retry.

Practice loads when this section enters view.