L-2 (Data Frame Part 1).Ipynb - Colab
L-2 (Data Frame Part 1).Ipynb - Colab
ipynb - Colab
# import libraries
import numpy as np
import pandas as pd
Mounted at /content/drive
RollNo Name Eco Maths
0 1 Arnab 18 57
1 2 Kritika 23 45
2 3 Divyam 51 37
3 4 Vivaan 40 60
4 5 Aaaroosh 18 27
0 1 Arnab 18 57
1 2 Kritika 23 45
2 3 Divyam 51 37
3 4 Vivaan 40 60
4 5 Aaaroosh 18 27
# nsmallest(n, column_label) gives the n smallest values in the column, creates a dataframe as its result
least2 = marks.nsmallest(2, "ECONOMICS")
print(least2)
# nlargest(n, column_label) gives the n largest values in the column, creates a dataframe as its result
great2 = marks.nlargest(2, "MATHS")
print(great2)
print(result)
print(type(result))
0 False
1 True
2 True
3 False
4 False
Name: Maths, dtype: bool
<class 'pandas.core.series.Series'>
P Q R S
0 2 1 14 52
1 9 20 30 46
2 8 12 18 12
3 7 5 52 83
count = df['P'].count()
print(count)
max_val=df['P'].max()
print ("Maximum Value of one Column P\n", max_val)
max_row=df.max(axis=1)
print ("Maximum Value Rowwise\n", max_row)
max_col=df.max(axis=0)
print ("Maximum Value Columnwise\n", max_col)
min_val=df['P'].min()
print ("Minimum Value of one Column P\n", min_val)
min_row=df.min(axis=1)
print ("Minimum Value Rowwise\n", min_row)
min_col=df.min(axis=0)
print ("Minimum Value Columnwise\n", min_col)
mean_val=df['P'].mean()
print ("Mean Value of one Column P\n", mean_val)
mean_row=df.mean(axis=1)
print ("Mean Value Rowwise\n", mean_row)
mean_col=df.mean(axis=0)
print ("Mean Value Columnwise\n", mean_col)
https://colab.research.google.com/drive/1Bos1V9K5-scUxXEBk7rNViiSpMC4k0wJ#scrollTo=A6cdItmM9Kkg&printMode=true 2/5
3/14/25, 4:35 PM L-2 (Data Frame Part 1).ipynb - Colab
dtype: float64
mode_val=df['P'].mode()
print ("Mode Value of one Column P\n", mode_val)
mode_row=df.mode(axis=1)
print ("Mode Value Rowwise\n", mode_row)
mode_col=df.mode(axis=0)
print ("Mode Value Columnwise\n", mode_col)
median_val=df['P'].median()
print ("Median Value of one Column P\n", median_val)
median_row=df.median(axis=1)
print ("Median Value Rowwise\n", median_row)
median_col=df.median(axis=0)
print ("Median Value Columnwise\n", median_col)
std_val=df['P'].std()
print ("Standard Deviation Value of one Column P\n",
std_val)
std_row=df.std(axis=1)
print ("Standard Deviation Value Rowwise\n", std_row)
std_col=df.std(axis=0)
print ("Standard Deviation Value Columnwise\n", std_col)
https://colab.research.google.com/drive/1Bos1V9K5-scUxXEBk7rNViiSpMC4k0wJ#scrollTo=A6cdItmM9Kkg&printMode=true 3/5
3/14/25, 4:35 PM L-2 (Data Frame Part 1).ipynb - Colab
3 37.703890
dtype: float64
Standard Deviation Value Columnwise
P 3.109126
Q 8.346656
R 17.078251
S 29.101833
dtype: float64
print(df.cov())
P Q R S
P 9.666667 22.000000 21.666667 -19.833333
Q 22.000000 69.666667 2.333333 -100.833333
R 21.666667 2.333333 291.666667 379.833333
S -19.833333 -100.833333 379.833333 846.916667
print(df.corr())
P Q R S
P 1.000000 0.847758 0.408047 -0.219198
Q 0.847758 1.000000 0.016369 -0.415118
R 0.408047 0.016369 1.000000 0.764239
S -0.219198 -0.415118 0.764239 1.000000
print(df)
print(df.cumsum(axis=0))
P Q R S
0 2 1 14 52
1 9 20 30 46
2 8 12 18 12
3 7 5 52 83
P Q R S
0 2 1 14 52
1 11 21 44 98
2 19 33 62 110
3 26 38 114 193
print(df)
print(df.cumsum(axis=1))
P Q R S
0 2 1 14 52
1 9 20 30 46
2 8 12 18 12
3 7 5 52 83
P Q R S
0 2 3 17 69
1 9 29 59 105
2 8 20 38 50
3 7 12 64 147
print(df)
print(df.cumprod(axis=0))
P Q R S
0 2 1 14 52
1 9 20 30 46
2 8 12 18 12
3 7 5 52 83
P Q R S
0 2 1 14 52
1 18 20 420 2392
2 144 240 7560 28704
3 1008 1200 393120 2382432
https://colab.research.google.com/drive/1Bos1V9K5-scUxXEBk7rNViiSpMC4k0wJ#scrollTo=A6cdItmM9Kkg&printMode=true 4/5
3/14/25, 4:35 PM L-2 (Data Frame Part 1).ipynb - Colab
https://colab.research.google.com/drive/1Bos1V9K5-scUxXEBk7rNViiSpMC4k0wJ#scrollTo=A6cdItmM9Kkg&printMode=true 5/5