పాండాస్ డేటాఫ్రేమ్‌లపై పూర్తి గైడ్: స్పైడర్‌లో దిగుమతి, కాపీలు, లక్షణాలు, ఇండెక్సింగ్ & ఎంపిక

 2 min read

YouTube video ID: 6DTFIKF8QIg

Source: YouTube video by NPTEL-NOC IITMWatch original video

PDF

పరిచయం

  • పాండాస్ లైబ్రరీ అనేది పైథాన్‌లో అధిక పనితీరు డేటా మానిప్యులేషన్, విశ్లేషణ కోసం ఓపెన్‑సోర్స్ టూల్.
  • "pandas" పేరు "panel data" (బహుళ‑డైమెన్షనల్ డేటా) నుండి వచ్చింది.

డేటాఫ్రేమ్ అంటే ఏమిటి?

  • రెండు‑మితీయ (rows, columns) టేబుల్‑లాంటిది.
  • ప్రతి వరుస (row) ఒక నమూనా/రికార్డు, ప్రతి కాలమ్ (column) ఒక చరరాశి (variable).
  • లేబుల్ చేయబడిన అక్షాలు (row index, column labels) ద్వారా డేటాను సులభంగా యాక్సెస్ చేయవచ్చు.

స్పైడర్‌లో డేటాను దిగుమతి చేయడం

  1. అవసరమైన లైబ్రరీలను దిగుమతి చేయండి: python import os import pandas as pd import numpy as np
  2. os.chdir() ద్వారా CSV ఫైల్ ఉన్న ఫోల్డర్‌కు వర్కింగ్ డైరెక్టరీని మార్చండి.
  3. pd.read_csv('cars.csv') ద్వారా CSV ఫైల్‌ను DataFrame (ఉదా: cars_data) గా చదవండి.
  4. DataFrame పేరు, టైప్, అంశాల సంఖ్యను Environment ట్యాబ్‌లో చూడవచ్చు.

DataFrame నిర్మాణాన్ని అర్థం చేసుకోవడం

  • మొదటి కాలమ్ సాధారణంగా ఇండెక్స్ (row labels).
  • రెండవ కాలమ్ (అనవసరమైన "Unnamed: 0") ను తొలగించవచ్చు: python cars_data = pd.read_csv('cars.csv', index_col=0)
  • కాలమ్‌లు: price, age, km, fuel_type, horsepower, metal_color, automatic, doors, weight, etc.

అసలు డేటా కాపీ సృష్టించడం

  • షాలో (shallow) కాపీ: df_copy = df లేదా df_copy = df.copy(deep=False)
  • కొత్త వేరియబుల్ అసలు DataFrame యొక్క రిఫరెన్స్ మాత్రమే; మార్పులు అసలుపై కూడా ప్రభావితం చేస్తాయి.
  • డీప్ (deep) కాపీ: df_deep = df.copy(deep=True)
  • పూర్తిగా కొత్త ఆబ్జెక్ట్; అసలు DataFrame కు ఎటువంటి ప్రభావం లేదు.

DataFrame లక్షణాలు (attributes)

  • Index (row labels): df.index
  • Columns (column labels): df.columns
  • Shape (rows, columns): df.shape
  • Size (మొత్తం అంశాలు): df.size
  • Memory usage (బైట్లలో): df.memory_usage()
  • Dimensions (ndim): df.ndim

ఇండెక్సింగ్ & ఎంపిక (Selection)

  1. head() & tail() – మొదటి/చివరి n వరుసలను చూడటానికి. python df.head(6) # మొదటి 6 వరుసలు df.tail(5) # చివరి 5 వరుసలు
  2. loc – లేబుల్‑ఆధారిత ఎంపిక. python df.loc[5, 'fuel_type'] # 5వ row, 'fuel_type' కాలమ్ విలువ df.loc[:, ['fuel_type', 'price']] # అన్ని rows, రెండు కాలమ్‌లు
  3. iat – integer‑based (position) ఎంపిక. python df.iat[5, 6] # 6వ row, 7వ కాలమ్ (0‑based)
  4. at – లేబుల్‑ఆధారిత scalar ఎంపిక. python df.at[5, 'fuel_type']
  5. .loc / .iloc ద్వారా స్లైసింగ్ కూడా చేయవచ్చు.

ముఖ్యమైన పాయింట్లు

  • DataFrame లో ఇండెక్స్, కాలమ్ లేబల్స్ స్పష్టంగా ఉండాలి; అవసరమైతే index_col లేదా drop ద్వారా సవరించండి.
  • షాలో కాపీ vs డీప్ కాపీ మధ్య తేడాను అర్థం చేసుకుని, అవసరానికి అనుగుణంగా ఎంపిక చేయండి.
  • shape, size, memory_usage() వంటి లక్షణాలు డేటాసెట్ పరిమాణాన్ని త్వరగా తెలుసుకోవడానికి సహాయపడతాయి.
  • loc, iat, at, iloc వంటి ఎంపిక పద్ధతులు పెద్ద డేటాసెట్‌లలో కూడా వేగవంతమైన యాక్సెస్‌ను అందిస్తాయి.

కోడ్ స్నిప్పెట్లు (సారాంశం)

import os, pandas as pd, numpy as np
os.chdir('D:/data')
df = pd.read_csv('cars.csv', index_col=0)
print(df.head())
print(df.shape)
print(df.memory_usage())
# షాలో కాపీ
shallow = df.copy(deep=False)
# డీప్ కాపీ
deep = df.copy()
# లేబుల్‑ఆధారిత ఎంపిక
price_of_5th = df.at[5, 'price']

పాండాస్ డేటాఫ్రేమ్‌లు రెండు‑మితీయ టేబుల్‑లాగా ఉండి, స్పైడర్‌లో CSV ఫైళ్లను సులభంగా దిగుమతి చేసి, ఇండెక్స్, కాలమ్‌లు, shape, memory వంటి లక్షణాలను పొందవచ్చు. షాలో లేదా డీప్ కాపీని ఎంచుకోవడం, అలాగే loc, iat, at వంటి ఎంపిక పద్ధతులను ఉపయోగించడం ద్వారా మీరు డేటాను సురక్షితంగా, సమర్థవంతంగా నిర్వహించగలరు.

Frequently Asked Questions

Who is NPTEL-NOC IITM on YouTube?

NPTEL-NOC IITM is a YouTube channel that publishes videos on a range of topics. Browse more summaries from this channel below.

Does this page include the full transcript of the video?

Yes, the full transcript for this video is available on this page. Click 'Show transcript' in the sidebar to read it.

డేటాఫ్రేమ్ అంటే ఏమిటి?

- రెండు‑మితీయ (rows, columns) టేబుల్‑లాంటిది. - ప్రతి వరుస (row) ఒక నమూనా/రికార్డు, ప్రతి కాలమ్ (column) ఒక చరరాశి (variable). - లేబుల్ చేయబడిన అక్షాలు (row index, column labels) ద్వారా డేటాను సులభంగా యాక్సెస్ చేయవచ్చు.

Helpful resources related to this video

If you want to practice or explore the concepts discussed in the video, these commonly used tools may help.

Links may be affiliate links. We only include resources that are genuinely relevant to the topic.

PDF