Data Cleaning & Preprocessing in Pandas in hindi
Data Cleaning & Preprocessing in Pandas – Complete Hindi Guide for Data Science
SEO Optimized Table of Contents – Data Cleaning & Preprocessing in Pandas
- Data Cleaning in Pandas (डेटा को साफ़ करने की प्रक्रिया)
- Handling Missing Values in Pandas (Missing Data को Handle करना)
- Removing Duplicate Data in Pandas (Duplicate Data हटाना)
- Data Type Conversion in Pandas (Data Type को सही करना)
- Data Normalization & Scaling in Pandas (Data को Normalize करना)
- Data Preprocessing in Pandas (Machine Learning से पहले Data तैयार करना)
Data Cleaning & Preprocessing in Pandas in Hindi
अगर आप Data Science, Machine Learning या Data Analysis की पढ़ाई कर रहे हो, तो आपको सबसे पहले एक बात समझनी होगी — Raw Data कभी भी सीधे काम का नहीं होता। Real world data हमेशा गंदा, अधूरा और गलत format में होता है। इसी data को usable बनाने की पूरी process को हम Data Cleaning & Preprocessing कहते हैं।
इस article में हम Pandas की मदद से Data Cleaning को बिल्कुल basic level से exam-oriented तरीके में समझेंगे, ताकि college exams, viva और practicals तीनों में clear रहे।
Data Cleaning in Pandas
Data Cleaning का मतलब होता है dataset से उन problems को हटाना या सुधारना, जो analysis या model के result को गलत बना सकती हैं। Pandas हमें powerful tools देता है जिससे हम data को आसानी से clean कर सकते हैं।
जब data clean नहीं होता, तब machine learning model गलत prediction करता है। इसलिए कहा जाता है — Better Data > Better Model।
Why Data Cleaning is Important
- Incorrect data गलत output देता है
- Missing values accuracy कम कर देती हैं
- Duplicate records result को bias करते हैं
- Wrong data type calculation को बिगाड़ देता है
Exams में अक्सर पूछा जाता है — Why data cleaning is required before analysis? इसका simple answer यही है कि clean data से ही correct decision लिया जा सकता है।
Handling Missing Values in Pandas
Dataset में सबसे common problem होती है Missing Values की।
Missing value का मतलब है कि किसी row या column में data मौजूद नहीं है।
Pandas में missing values को NaN से represent किया जाता है।
Why Missing Values Occur
- Data collection में error
- User ने information नहीं दी
- Sensor या system failure
अगर missing values को ignore कर दिया जाए, तो average, sum और prediction सब गलत हो सकता है। इसलिए Pandas में इन्हें handle करना जरूरी होता है।
Checking Missing Values
सबसे पहले हमें यह पता करना होता है कि data में missing values हैं या नहीं।
df.isnull()
df.isnull().sum()
यह code हर column में missing values की count दिखा देता है, जो exam practical में बहुत common question है।
Removing Missing Values
अगर missing values बहुत कम हैं, तो हम उन्हें directly delete भी कर सकते हैं।
df.dropna()
लेकिन ध्यान रहे — drop करने से data loss होता है। इसलिए exam answer में हमेशा लिखना चाहिए कि drop तभी करें जब missing data insignificant हो।
Filling Missing Values
Most of the time missing values को fill करना बेहतर होता है। Numeric data में हम mean या median use करते हैं।
df.fillna(df.mean())
Text data के case में mode या custom value use की जाती है।
df['column_name'].fillna("Not Available")
Exam point of view से यह याद रखें — Mean, Median, Mode filling is called Data Imputation।
Removing Duplicate Data in Pandas
Duplicate data का मतलब होता है same record का बार-बार repeat होना। यह problem surveys, forms और merged datasets में बहुत ज्यादा होती है।
Duplicate records analysis को mislead करते हैं और model को biased बना देते हैं। इसलिए preprocessing में duplicates remove करना बहुत जरूरी step है।
Identifying Duplicate Rows
Pandas में duplicate rows पहचानने के लिए simple method है:
df.duplicated()
यह True/False return करता है और बताता है कि कौन-सी row duplicate है।
Removing Duplicate Rows
Duplicate rows को remove करने के लिए Pandas का built-in function use किया जाता है:
df.drop_duplicates()
अगर किसी specific column के basis पर duplicates हटाने हों, तो:
df.drop_duplicates(subset=['column_name'])
Exams में यह question बहुत common है — How to remove duplicate records in Pandas? इसका direct answer यही code है।
Why Duplicate Data is Dangerous
- Average और count गलत हो जाते हैं
- Model overfit हो सकता है
- Business decision गलत हो सकता है
इसलिए हमेशा analysis से पहले duplicate data check करना best practice माना जाता है।
Data Type Conversion in Pandas
Real world dataset में एक बहुत common problem होती है Wrong Data Type। कई बार numeric data text (object) के रूप में store होता है या date simple string बनकर रह जाती है। ऐसे data पर calculation करना possible नहीं होता।
इसलिए Data Type Conversion Data Cleaning का बहुत important part है। Pandas हमें data type बदलने के आसान और safe methods देता है।
Why Data Type Conversion is Required
- Calculation और comparison सही करने के लिए
- Memory usage optimize करने के लिए
- Machine Learning model को error से बचाने के लिए
Exam point of view से याद रखो — Wrong data type leads to wrong analysis।
Checking Data Types
सबसे पहले यह देखना जरूरी होता है कि dataset में कौन-सा column किस data type का है।
df.dtypes
यह command हर column का data type दिखा देती है, जो practical exam में अक्सर पूछा जाता है।
Converting Data Types using astype()
Pandas में data type बदलने का सबसे common तरीका है astype()।
df['age'] = df['age'].astype(int)
इस example में age column को integer में convert किया गया है। अगर data clean नहीं है, तो conversion से पहले missing values handle करना जरूरी होता है।
Converting Date and Time Data
Date और Time data analysis में बहुत important होता है।
Pandas में date conversion के लिए to_datetime() use किया जाता है।
df['date'] = pd.to_datetime(df['date'])
यह method string date को proper datetime format में convert कर देता है, जिससे sorting और filtering आसान हो जाती है।
Data Normalization & Scaling in Pandas
जब dataset में अलग-अलग range के values होते हैं, तब machine learning model confuse हो सकता है। इस problem को solve करने के लिए Normalization और Scaling use किया जाता है।
Example के तौर पर — Salary हजारों में हो और Age दो digit में, तो model salary को ज्यादा importance दे देता है।
What is Data Normalization
Data Normalization का मतलब है data को एक common scale में लाना, आमतौर पर 0 से 1 के बीच।
Normalization से features balanced हो जाते हैं और model fair decision ले पाता है।
Min-Max Normalization Formula
Exams में formula बहुत important होता है:
(X − Min) / (Max − Min)
यह formula हर value को 0 और 1 के बीच convert कर देता है।
Normalization using Pandas
df['normalized_column'] =
(df['column'] - df['column'].min()) /
(df['column'].max() - df['column'].min())
यह pure Pandas approach है, जो theory और practical दोनों के लिए perfect है।
What is Scaling
Scaling का मतलब होता है data की range को change करना, लेकिन values के relation को same रखना।
Scaling mainly algorithms जैसे Linear Regression, KNN, SVM के लिए जरूरी होती है।
Difference Between Normalization and Scaling
| Normalization | Scaling |
|---|---|
| 0 से 1 के बीच data | Mean और standard deviation पर based |
| Range fixed होती है | Range fixed नहीं होती |
| Simple datasets के लिए | Advanced ML algorithms के लिए |
यह comparison table exam answers में directly use किया जा सकता है।
Data Preprocessing in Pandas
Data Preprocessing एक complete process है जिसमें raw data को machine learning ready बनाया जाता है। यह Data Cleaning से थोड़ा broader concept है।
Simple words में — Preprocessing = Cleaning + Transformation + Preparation
Steps of Data Preprocessing
- Handling Missing Values
- Removing Duplicate Data
- Data Type Conversion
- Normalization and Scaling
- Feature Selection
Exam में अक्सर पूछा जाता है — List the steps involved in data preprocessing। यह list वही standard answer है।
Feature Selection Concept
Feature selection का मतलब होता है unnecessary columns को हटाना और useful columns को retain करना।
Extra features model को slow बनाते हैं और accuracy को भी reduce कर सकते हैं।
Dropping Unwanted Columns
df.drop(['unnecessary_column'], axis=1, inplace=True)
यह Pandas का basic preprocessing operation है, जो हर practical student को आना चाहिए।
Encoding Categorical Data (Basic Idea)
Machine learning models text data को directly understand नहीं करते। इसलिए categorical values को numeric form में convert किया जाता है।
Example: Male → 1 Female → 0
df['gender'] = df['gender'].map({'Male':1, 'Female':0})
यह process Encoding कहलाती है और preprocessing का important part है।
Why Data Preprocessing is Important for Machine Learning
- Model accuracy improve होती है
- Training faster होती है
- Overfitting का risk कम होता है
- Prediction reliable बनता है
इसलिए कहा जाता है — 80% work Data Preprocessing में होता है, 20% Model training में।
College exams, competitive exams और interviews में Data Cleaning & Preprocessing in Pandas एक high-weightage topic माना जाता है। अगर concepts clear हैं, तो marks guaranteed होते हैं।
FAQs
Data Cleaning & Preprocessing in Pandas in hindi का मतलब है raw data को साफ़ करना और analysis या Machine Learning के लिए तैयार करना। इसमें missing values handle करना, duplicate data हटाना, data type सही करना और data को normalize करना शामिल होता है। यह process इसलिए जरूरी है क्योंकि बिना clean data के सही result नहीं मिल सकता।
Pandas में Missing Values को handle करने के लिए isnull(), dropna() और fillna() methods use किए जाते हैं।
Missing values को delete भी किया जा सकता है या फिर mean, median, mode से fill किया जाता है।
Exam में इसे Data Imputation भी कहा जाता है।
Data Cleaning in Pandas in hindi इसलिए जरूरी है क्योंकि raw data में errors, missing values और duplicates होते हैं। अगर data clean नहीं होगा तो analysis और Machine Learning model गलत output देगा। Clean data से accuracy बढ़ती है और decision सही होते हैं।
Pandas में duplicate data remove करने के लिए duplicated() और drop_duplicates() methods use किए जाते हैं।
यह methods same records को पहचानकर dataset से हटा देते हैं।
Duplicate data हटाना preprocessing का important step माना जाता है।
Data Type Conversion in Pandas in hindi का मतलब है किसी column के data type को सही format में बदलना।
जैसे string को integer, float या date में convert करना।
इसके लिए astype() और to_datetime() methods use किए जाते हैं।
Data Preprocessing in Pandas in hindi Machine Learning के लिए इसलिए जरूरी है क्योंकि ML models raw data को directly समझ नहीं पाते। Preprocessing से data clean, balanced और numeric बनता है, जिससे model की accuracy और performance improve होती है। यही reason है कि preprocessing को ML का सबसे important step माना जाता है।