2.Indexing and Slicing In Pandas
Indexing And Slicing In Pandas
Loading Libraries :
import pandas as pdLoading Dataset :
heroes=pd.read_csv('heroes.csv')
heroes.head()sr
name
Gender
Eye color
Race
Hair color
Height
Publisher
Skin color
Alignment
Weight
Setting and Remove Indexes :
Setting an index :
sr
name
Gender
Eye color
Race
Hair color
Height
Skin color
Alignment
Weight
Resetting index to default :
index
sr
name
Gender
Eye color
Race
Hair color
Height
Publisher
Skin color
Alignment
Weight
Reset Index and drop previous index:
sr
name
Gender
Eye color
Race
Hair color
Height
Skin color
Alignment
Weight
Subsetting with .loc[]
sr
name
Gender
Eye color
Race
Hair color
Height
Publisher
Skin color
Alignment
Weight
Using .loc[]
sr
name
Gender
Eye color
Race
Hair color
Height
Skin color
Alignment
Weight
Setting multi-level indexes
Index heroes by Alignment & Publisher
sr
name
Gender
Eye color
Race
Hair color
Height
Skin color
Weight
Slicing index values
sr
name
Gender
Eye color
Race
Hair color
Height
Skin color
Weight
Subset rows from 'bad' to 'good'
sr
name
Gender
Eye color
Race
Hair color
Height
Skin color
Weight
Subset rows from 'good','DC Comics' to 'neutral','Marvel Comics'
Slicing series
Subsetting by row/column number
To get the 5th row and 2nd column Value
To get First 5 Rows
sr
name
Gender
Eye color
Race
Hair color
Height
Publisher
Skin color
Alignment
Weight
To get All rows of Column 'name','Gender','Eye color':
name
Gender
Eye color
To get 10 rows of Column 'name','Gender','Eye color':
name
Gender
Eye color
Last updated
