Feedback Form

Importing CSV, Excel, JSON in Pandas in hindi

Importing CSV, Excel, JSON in Pandas (Hindi Guide)

Importing CSV, Excel, JSON in Pandas in Hindi

Data Science और Machine Learning की पढ़ाई में Pandas एक बहुत ही important Python library है। College exams में अक्सर पूछा जाता है कि Pandas में data को अलग-अलग file formats से कैसे import किया जाता है। इस article में हम बिल्कुल basic से शुरू करेंगे ताकि beginner students को भी आसानी से समझ आ जाए।

Pandas का सबसे बड़ा use यही है कि हम real world data को CSV, Excel और JSON जैसी files से read करके analysis कर सकें। Exams में theory के साथ-साथ syntax भी पूछा जाता है, इसलिए हर concept को simple language में step-by-step समझाया गया है।

Importing CSV File in Pandas

CSV का full form होता है Comma Separated Values। यह सबसे common data file format है, जिसे almost हर organization use करती है। CSV file में data rows और columns के form में होता है, और values comma से separate होती हैं।

Pandas में CSV file को import करने के लिए read_csv() function का use किया जाता है। Exam point of view से यह function बहुत important है, क्योंकि direct question आ सकता है कि CSV file Pandas में कैसे load करते हैं।

Basic Syntax of read_csv()

CSV file को read करने का basic syntax बहुत simple होता है। सबसे पहले Pandas library को import किया जाता है, फिर file path pass करके data को DataFrame में load किया जाता है।

import pandas as pd
data = pd.read_csv("student_data.csv")

ऊपर दिए गए code में pd Pandas का short name है। student_data.csv file का data अब data नाम के DataFrame में store हो जाएगा। Exam में अक्सर यही पूछा जाता है कि CSV file DataFrame में कैसे convert होती है।

Important Parameters of read_csv()

सिर्फ file read करना ही काफी नहीं होता। कई बार CSV file में header नहीं होता, या separator comma की जगह semicolon होता है। ऐसे cases में parameters बहुत काम आते हैं।

  • sep – जब values comma के अलावा किसी और symbol से separated हों।
  • header – अगर file में column names नहीं हैं।
  • encoding – जब file UTF-8 या किसी special encoding में हो।
data = pd.read_csv("student_data.csv", sep=",", header=0)

College exams में theoretical question भी आता है कि CSV import करते समय कौन-कौन से parameters use किए जाते हैं। इसलिए इन keywords को याद रखना बहुत जरूरी है।

Why CSV is Important in Data Analysis

CSV files lightweight होती हैं और easily readable होती हैं। Data analysis में large datasets ज्यादातर CSV format में ही available होते हैं। Pandas CSV files को fast और efficiently handle करता है।

Exam perspective से CSV इसलिए important है क्योंकि यह real world data का सबसे common example है। Practical questions में CSV file देकर Pandas operations perform करने को कहा जाता है।

Importing Excel File in Pandas

Excel files का use colleges, offices और companies में सबसे ज्यादा होता है। Excel file generally .xls या .xlsx format में होती है। Pandas में Excel file import करने के लिए read_excel() function का use किया जाता है।

Exams में CSV और Excel import के बीच difference भी पूछा जा सकता है, इसलिए दोनों को clear तरीके से समझना जरूरी है।

Basic Syntax of read_excel()

Excel file import करने का syntax भी CSV जैसा ही होता है, बस function का नाम अलग होता है।

data = pd.read_excel("marks.xlsx")

इस code से पूरी Excel sheet Pandas DataFrame में load हो जाती है। अगर file में multiple sheets हों, तो by default पहली sheet read होती है।

Reading Specific Sheet from Excel

कई Excel files में एक से ज्यादा sheets होती हैं। ऐसे case में हमें बताना पड़ता है कि कौन-सी sheet read करनी है। इसके लिए sheet_name parameter use किया जाता है।

data = pd.read_excel("marks.xlsx", sheet_name="Semester1")

Exam में direct question आ सकता है कि Excel file की specific sheet कैसे import करते हैं। इसलिए इस parameter को specially याद रखें।

Common Excel Import Parameters

Excel file import करते समय भी कुछ important parameters होते हैं, जिनका use practical problems में किया जाता है।

  • sheet_name – specific sheet read करने के लिए।
  • header – column names define करने के लिए।
  • usecols – only selected columns read करने के लिए।
data = pd.read_excel("marks.xlsx", usecols="A:C")

यह code Excel file के सिर्फ A से C columns को DataFrame में load करेगा। Data analysis में unnecessary columns हटाने के लिए यह बहुत useful होता है।

CSV vs Excel in Pandas

Exams में अक्सर CSV और Excel के बीच comparison पूछा जाता है। नीचे table के through difference को easy तरीके से समझ सकते हैं।

CSV File Excel File
Simple text format Binary / formatted file
Single sheet data Multiple sheets supported
read_csv() function read_excel() function

यह comparison exam answers लिखते समय बहुत help करता है। अगर short note या difference question आए, तो ऐसे points आसानी से लिखे जा सकते हैं।

Importing JSON File in Pandas

अब हम तीसरे और बहुत important topic की बात करते हैं, जो है JSON file import करना। JSON का full form होता है JavaScript Object Notation। यह format आज के time में APIs, web applications और databases में सबसे ज्यादा use होता है।

College exams में JSON related questions इसलिए पूछे जाते हैं, क्योंकि real-world data अक्सर JSON format में ही मिलता है। Pandas JSON data को easily DataFrame में convert कर सकता है।

Basic Structure of JSON Data

JSON data key-value pairs में होता है। Keys strings होती हैं और values numbers, strings, list या objects हो सकते हैं। यह structure dictionary जैसा होता है, इसलिए Python students को समझने में easy लगता है।

Example के तौर पर student data JSON में कुछ इस तरह दिख सकता है – name, roll number और marks एक object के form में store होते हैं।

Basic Syntax of read_json()

Pandas में JSON file import करने के लिए read_json() function use किया जाता है। इसका syntax बहुत simple है और exam में direct पूछा जा सकता है।

import pandas as pd
data = pd.read_json("students.json")

इस code से पूरी JSON file Pandas DataFrame में convert हो जाती है। अगर JSON properly formatted है, तो Pandas automatically rows और columns बना देता है।

JSON Orientation in Pandas

JSON data हमेशा same format में नहीं होता। कभी-कभी data records के form में होता है और कभी columns के form में। Pandas में इस problem को handle करने के लिए orient parameter दिया गया है।

  • records – जब JSON list of dictionaries हो।
  • columns – जब keys column names हों।
  • index – जब keys index represent करें।
data = pd.read_json("students.json", orient="records")

Exam में theory question आ सकता है कि JSON orientation क्या होती है। इसलिए इन terms को समझना और याद रखना बहुत जरूरी है।

Importing JSON from URL

Pandas की एक बहुत useful feature यह है कि वह direct URL से भी JSON data read कर सकता है। यह feature APIs से data fetch करने में काम आता है। Competitive exams और advanced college syllabus में यह point include होता है।

url = "https://example.com/data.json"
data = pd.read_json(url)

इस तरह Pandas web-based JSON data को भी DataFrame में convert कर देता है। Real-world data analysis में इसका बहुत बड़ा role है।

CSV, Excel, JSON – Practical Comparison

अब तक हमने CSV, Excel और JSON तीनों formats को अलग-अलग समझा। Exam point of view से इनके बीच difference और use-case समझना बहुत important है।

Format Main Use Pandas Function
CSV Tabular text data read_csv()
Excel Spreadsheet data read_excel()
JSON Structured & API data read_json()

इस तरह के tables answers को structured और scoring बनाते हैं। Examiner को भी clear difference दिखाई देता है।

Common Errors While Importing Data

Students अक्सर exam और practical दोनों में कुछ common mistakes करते हैं। इन errors को समझना जरूरी है ताकि answers और code दोनों correct हों।

  • Wrong file path देना, जिससे FileNotFoundError आ जाता है।
  • CSV separator को ignore करना।
  • Excel sheet name गलत लिख देना।
  • Improper JSON structure की वजह से error आना।

अगर student इन mistakes को avoid कर ले, तो Pandas में data import करना बहुत smooth हो जाता है।

Why Data Import is Important in Exams

Pandas का पूरा concept data analysis पर based है। अगर data import करना ही नहीं आता, तो आगे analysis possible नहीं होता। इसलिए examiners सबसे पहले यही check करते हैं कि student data load कर सकता है या नहीं।

Practical exams में CSV या Excel file दी जाती है और students से कहा जाता है कि उसे DataFrame में read करके operations perform करें। Theory exams में functions, parameters और differences पूछे जाते हैं।

Exam-Oriented Summary Points

नीचे कुछ short points दिए गए हैं, जो revision के time बहुत helpful होते हैं। इन्हें answers में direct use किया जा सकता है।

  • Pandas में data import करने के लिए read functions use होते हैं।
  • CSV files ke liye read_csv() use hota hai।
  • Excel files ke liye read_excel() use hota hai।
  • JSON files ke liye read_json() use hota hai।
  • Imported data Pandas DataFrame ke form me store hota hai।

Agar student in points ko clear rakhता है, तो Pandas ke data importing questions easily solve ho jaate hain। Yeh topic Data Science syllabus ka base hai aur aage ke topics ka foundation bhi।

FAQs

आपका अगला टॉपिक पढ़े Handling Missing Values in Pandas in hindi
Pandas एक Python library है जिसका use data analysis के लिए किया जाता है। Data importing in hindi इसलिए जरूरी है क्योंकि CSV, Excel और JSON जैसी files से data लाए बिना analysis possible नहीं होता। College exams में Pandas का पहला step यही माना जाता है।
Pandas में CSV file import करने के लिए read_csv() function use किया जाता है। CSV file comma separated होती है और Pandas उसे direct DataFrame में convert कर देता है। Exam में यह सबसे ज्यादा पूछा जाने वाला question है।
Excel file import करने के लिए Pandas का read_excel() function use किया जाता है। Agar Excel file में multiple sheets हों, तो sheet_name parameter के through specific sheet को read किया जा सकता है।
JSON file import करने के लिए Pandas में read_json() function use किया जाता है। JSON data key-value format में होता है और Pandas उसे automatically rows और columns में convert कर देता है।
Exam point of view से तीनों formats important हैं। CSV basic data handling के लिए, Excel practical use के लिए और JSON real-world API data के लिए पूछा जाता है। इसलिए students को तीनों का knowledge होना चाहिए।
Common errors में wrong file path देना, CSV separator गलत होना, Excel sheet name mismatch होना और JSON structure गलत होना शामिल है। In errors को समझना exams और practical दोनों के लिए जरूरी है।