L-3 (Data Frame Part 2).Ipynb - Colab
L-3 (Data Frame Part 2).Ipynb - Colab
ipynb - Colab
print(df)
print(df.describe(include=['object']))
print(df.describe(include=['number']))
Age Rating
count 12.000000 12.000000
mean 32.500000 3.743333
std 8.816307 0.661628
min 23.000000 2.560000
25% 25.750000 3.230000
50% 30.000000 3.790000
75% 35.500000 4.132500
max 51.000000 4.800000
print(df.describe(include='all'))
Changed Frame
https://colab.research.google.com/drive/1r50IfA2defohJdwiqmLmTdqZ_JIP0wf2#printMode=true 1/5
3/14/25, 4:36 PM L-3 (Data Frame Part 2).ipynb - Colab
RollNo Name Eco
0 1 Arnab 18
1 2 Kritika 23
2 3 Divyam 51
3 4 Vivaan 40
4 5 Aaaroosh 18
RollNo Name
0 1 Arnab
2 3 Divyam
3 4 Vivaan
# Create a sample student dataset consisting of 5 columns – age, section, city, gender, and favorite color.
# This dataset will contain both numerical as well as categorical variables:
https://colab.research.google.com/drive/1r50IfA2defohJdwiqmLmTdqZ_JIP0wf2#printMode=true 2/5
3/14/25, 4:36 PM L-3 (Data Frame Part 2).ipynb - Colab
# select rows with multiple conditions
print(data.loc[(data.age >= 12) & (data.gender == 'M')])
city gender
1 Delhi F
2 Mumbai F
3 Delhi M
4 Mumbai M
6 Mumbai F
data.index=['a','b','c','d','e','f','g']
print(data)
https://colab.research.google.com/drive/1r50IfA2defohJdwiqmLmTdqZ_JIP0wf2#printMode=true 3/5
3/14/25, 4:36 PM L-3 (Data Frame Part 2).ipynb - Colab
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-46-b83772436b9b> in <cell line: 1>()
----> 1 data.loc[0:2] # error as labels are 'a' to 'g'
6 frames
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in _maybe_cast_slice_bound(self, label, side, kind)
6621 # reject them, if index does not contain label
6622 if (is_float(label) or is_integer(label)) and label not in self:
-> 6623 raise self._invalid_indexer("slice", label)
6624
6625 return label
TypeError: cannot do slice indexing on Index with these indexers [0] of type int
#iloc()
# select rows with indexes
data.iloc[[0,2]]
a 10 A Gurgaon M red
c 13 M Mumbai F yellow
section gender
a A M
c M F
b 22 S Pune F NaN
c 13 M Mumbai F yellow
city gender
b Pune F
c Mumbai F
RollNo Name
0 1 Arnab
2 3 Divyam
3 4 Vivaan
RollNo Name
R1 1 Arnab
R3 3 Divyam
R4 4 Vivaan
https://colab.research.google.com/drive/1r50IfA2defohJdwiqmLmTdqZ_JIP0wf2#printMode=true 4/5
3/14/25, 4:36 PM L-3 (Data Frame Part 2).ipynb - Colab
https://colab.research.google.com/drive/1r50IfA2defohJdwiqmLmTdqZ_JIP0wf2#printMode=true 5/5