Python Pandas परिचय
In this page:
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?
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
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
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
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
import pandas as pd
df = pd.DataFrame({"age": [30, 25, 40]})
print(df[df["age"] > 28]) # boolean mask keeps only matching rows
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first:
- Python NumPy Introduction
- Python NumPy Arrays
- Python Pandas Introduction
- Python Pandas DataFrame
- Python Matplotlib Basics
- Python Data Visualization
- Python Statistics Module
- Python CSV & Data Analysis
- Python requests Module
- Python JSON & APIs
- Python Web Scraping Basics
- Python Flask Introduction
- Python Django Introduction
- Python MongoDB