Pandas DataFrames లో డేటా రకాలు: పూర్తి గైడ్
పరిచయం
ఈ లెక్చర్లో pandas DataFramesలోని వివిధ డేటా రకాలపై లోతైన అవగాహనను పొందుతాం. ముందున్న సెషన్లో pandas ను ఇంపోర్ట్ చేయడం, CSV ఫైళ్లను లోడ్ చేయడం, డేటా కాపీ, లక్షణాలు, ఇండెక్సింగ్ వంటి అంశాలు చర్చించాం. ఇప్పుడు ప్రతి కాలమ్లోని డేటా రకాలను ఎలా గుర్తించాలి, వాటిని ఎలా నిర్వహించాలి, మరియు విశ్లేషణలో వాటి ప్రాముఖ్యత ఏమిటో తెలుసుకుంటాం.
1. pandas లో ప్రధాన డేటా రకాలు
- సంఖ్యా రకాలు (Numeric)
int64– పూర్తి సంఖ్యలు (ఉదా: 10, -5)float64– దశాంశ సంఖ్యలు (ఉదా: 10.53, -3.14)- అక్షర (String) రకాలు
object– స్ట్రింగ్లు, మిశ్రమ విలువలు, లేదాNaNవంటి ప్రత్యేక విలువలుcategory– పరిమిత సంఖ్యలో ప్రత్యేక విలువలతో ఉన్న స్ట్రింగ్లు, మెమరీ సామర్థ్యాన్ని పెంచుతుంది
2. డేటా రకాలను ఎలా తనిఖీ చేయాలి
import pandas as pd
df = pd.read_csv('cars.csv')
print(df.dtypes) # ప్రతి కాలమ్ యొక్క dtype ను చూపిస్తుంది
df.dtypes ఒక Series ను ఇస్తుంది, అందులో ప్రతి కాలమ్ పేరు మరియు దాని dtype ఉంటుంది.
3. ప్రతి dtype యొక్క గణన (Count)
dtype_counts = df.dtypes.value_counts()
print(dtype_counts)
ఇది DataFrame లో int64, float64, object, category వంటి dtype ల సంఖ్యను చూపిస్తుంది.
4. నిర్దిష్ట dtype ఆధారంగా కాలమ్లను ఎంపిక చేయడం
numeric_cols = df.select_dtypes(include=['int64','float64']).columns
category_cols = df.select_dtypes(include=['category']).columns
object_cols = df.select_dtypes(include=['object']).columns
select_dtypes ద్వారా మీరు సంఖ్యా, వర్గీకరణ, లేదా స్ట్రింగ్ కాలమ్లను సులభంగా పొందవచ్చు.
5. dtype ను మార్చడం (Conversion)
- object → category (మెమరీ ఆదా):
python df['color'] = df['color'].astype('category') - object → numeric (సంఖ్యా ఆపరేషన్ల కోసం):
python df['price'] = pd.to_numeric(df['price'], errors='coerce')errors='coerce'అనేది మార్చలేని విలువలనుNaNగా మార్చుతుంది.
6. DataFrame సంక్షిప్త సారాంశం (info)
df.info()
- మొత్తం రికార్డుల సంఖ్య
- ప్రతి కాలమ్లో non‑null విలువల సంఖ్య
- ప్రతి కాలమ్ యొక్క dtype
- మెమరీ వినియోగం
7. ప్రత్యేక విలువల (Unique) జాబితా
unique_colors = df['color'].unique()
print(unique_colors)
numpy.unique లేదా pandas Series.unique() ద్వారా మీరు ఒక కాలమ్లోని అన్ని ప్రత్యేక విలువలను పొందవచ్చు. ఇది వర్గీకరణ డేటాను విశ్లేషించడానికి ముఖ్యమైనది.
8. సాధారణ సమస్యలు & పరిష్కారాలు
- స్ట్రింగ్లో సంఖ్యా విలువలు –
objectdtype గా చదవబడుతుంది; సంఖ్యా ఆపరేషన్లకుastype(int)లేదాpd.to_numericద్వారా మార్చాలి. NaNవిలువలు – pandas లోNaNనుfloatdtype లో నిల్వ చేస్తుంది;fillna()లేదాdropna()ద్వారా నిర్వహించాలి.- వర్గీకరణ (category) కాలమ్లు తప్పుగా object గా చదవబడితే –
astype('category')ద్వారా మార్చి, మెమరీను తగ్గించవచ్చు.
9. సమగ్ర వర్క్ఫ్లో
- డేటా లోడ్ →
pd.read_csvలేదా ఇతర రీడర్. df.info()ద్వారా మొత్తం నిర్మాణాన్ని తనిఖీ.df.dtypesద్వారా ప్రతి కాలమ్ dtype ను తెలుసుకో.value_counts()లేదాselect_dtypesద్వారా dtype ల గణన/ఎంపిక.- అవసరమైతే dtype మార్పు (object → numeric, object → category).
df.describe(),df['col'].unique()వంటి ఫంక్షన్లతో లోతైన విశ్లేషణ.
10. ముగింపు
డేటా రకాలు pandas లో విశ్లేషణ ఖచ్చితత్వాన్ని నిర్ణయిస్తాయి. సరైన dtype ఎంపిక ద్వారా మీరు గణన వేగాన్ని, మెమరీ వినియోగాన్ని, మరియు తప్పు ఫలితాలను నివారించవచ్చు. ఈ గైడ్లోని స్టెప్పులను అనుసరించడం ద్వారా మీరు DataFrames ను సమర్థవంతంగా నిర్వహించి, అవసరమైన విశ్లేషణలను సులభంగా చేయగలరు.
DataFrames లోని ప్రతి కాలమ్ యొక్క డేటా రకాన్ని ఖచ్చితంగా గుర్తించి, అవసరమైతే సరైన dtype కు మార్చడం ద్వారా మీరు విశ్లేషణ ఖచ్చితత్వాన్ని, పనితీరును, మరియు మెమరీ సామర్థ్యాన్ని గరిష్టంగా పొందవచ్చు.
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.
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.