← Back to Python Course | Chapter 13: Data Science & Web | Lesson 3 of 14

Python Pandas परिचय

Pandas आपको data की tables के साथ काम करने में मदद करता है, जैसे code से control किया जाने वाला spreadsheet। आप rows और columns देख सकते हैं और जो चाहिए उसे filter कर सकते हैं।
Syntax
python
import pandas as pd

series = pd.Series([item1, item2])
df = pd.read_csv("file.csv")

Pandas क्या है?

Pandas real-world data analysis के लिए उपयुक्त labeled, heterogeneous data structures जोड़ने के लिए NumPy पर बना है: data के एक labeled column के लिए Series, और row व column दोनों labels वाली एक पूरी two-dimensional table के लिए DataFrame -- इसे पूरी तरह code में manipulate किए जा सकने वाला spreadsheet समझें।

उदाहरण: What is Pandas?

python
import pandas as pd
s = pd.Series([1, 2, 3])  # one labeled column of data
print(s)

DataFrames बनाना

आप आमतौर पर एक DataFrame column-name-to-list mappings वाले dictionary से, row dictionaries की list से, या pd.read_csv() जैसे functions से सीधे किसी file से पढ़कर बनाते हैं। इनमें से हर तरीका अंत में labeled rows और columns की एक जैसी table-जैसी structure बनाता है।

उदाहरण: Creating DataFrames

python
import pandas as pd
df = pd.DataFrame({"name": ["Alex", "Sam"], "age": [30, 25]})  # dict of columns becomes a table
print(df)

Rows और Columns तक पहुँचना

Label-based indexing के लिए .loc[] rows और columns को उनके असली labels से चुनता है, जबकि .iloc[] labels चाहे जो भी कहें, raw positional index से चुनता है।

इन दोनों को गड्डमड्ड करना एक बहुत आम bug का कारण है, खासकर किसी DataFrame की rows filter या reorder हो जाने के बाद।

उदाहरण: Accessing Rows and Columns

python
import pandas as pd
df = pd.DataFrame({"name": ["Alex", "Sam"], "age": [30, 25]})
print(df.loc[0])  # selects by label
print(df.iloc[0])  # selects by positional index

Data Description

.info() हर column का dtype और non-null count बताता है, जबकि .describe() हर numeric column के लिए एक साथ summary statistics (mean, standard deviation, quartiles) निकालता है।

नया data load करने के तुरंत बाद दोनों चलाना स्पष्ट रूप से गलत types या अप्रत्याशित missing values पकड़ने का तेज़ तरीका है।

उदाहरण: Data Description

python
import pandas as pd
df = pd.DataFrame({"age": [30, 25, 40]})
print(df.describe())  # mean, std, quartiles for every numeric column

Basic Filtering

किसी boolean condition से rows filter करना, जैसे df[df[age] > 30], DataFrame के index पर एक mask बनाता है और सिर्फ matching rows लौटाता है -- यह वही pattern है जो NumPy की boolean indexing में है, बस table के labeled columns में स्वाभाविक रूप से फैला हुआ।

उदाहरण: Basic Filtering

python
import pandas as pd
df = pd.DataFrame({"age": [30, 25, 40]})
print(df[df["age"] > 28])  # boolean mask keeps only matching rows
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.