import numpy as np
import pandas as pd
np.random.rand(2)
array([0.78790637, 0.53467687])
arr = np.random.rand(5,5)
np.random.randint(10,100,[5,5])
array([[54, 91, 20, 58, 76],
[73, 22, 17, 51, 36],
[45, 34, 78, 81, 65],
[78, 73, 71, 69, 60],
[89, 82, 94, 17, 53]])
arr = np.random.rand(5,5)
arr = arr * 100
arr
array([[13.89907094, 6.02328741, 55.97452927, 64.95275007, 44.03135306],
[47.80695829, 74.74754359, 42.76571814, 55.0118051 , 14.85592332],
[70.57823706, 25.95461094, 86.24479057, 47.63141218, 23.6972414 ],
[49.75231494, 26.71780326, 66.7419534 , 63.97874405, 48.17081941],
[29.88279858, 31.61411307, 78.52130349, 94.1716773 , 18.83228245]])
arr = arr.astype(int)
arr
array([[13, 6, 55, 64, 44],
[47, 74, 42, 55, 14],
[70, 25, 86, 47, 23],
[49, 26, 66, 63, 48],
[29, 31, 78, 94, 18]])
arr
array([[13, 6, 55, 64, 44],
[47, 74, 42, 55, 14],
[70, 25, 86, 47, 23],
[49, 26, 66, 63, 48],
[29, 31, 78, 94, 18]])
pd.DataFrame(arr)
students = []
subjects = []
enter name of subjectk
students
['Soumya', 'Chandan', 'Mukesh', 'Ashish', 'Sarat']
subjects
['English', 'Maths', 'Physics', 'Chemistry', 'Biology']
for i in range(5):
stu = input("enter name of subject")
subjects.append(stu)
enter name of subjectEnglish
enter name of subjectMaths
enter name of subjectPhysics
enter name of subjectChemistry
enter name of subjectBiology
for i in range(5):
stu = input("enter name of student")
students.append(stu)
enter name of studentSoumya
enter name of studentChandan
enter name of studentMukesh
enter name of studentAshish
enter name of studentSarat
arr
array([[13, 6, 55, 64, 44],
[47, 74, 42, 55, 14],
[70, 25, 86, 47, 23],
[49, 26, 66, 63, 48],
[29, 31, 78, 94, 18]])
data = pd.DataFrame(arr, columns=subjects, index=students)
data
data.loc["Mukesh"]
English 70
Maths 25
Physics 86
Chemistry 47
Biology 23
Name: Mukesh, dtype: int32
data.iloc[1:3]
data["Average"] = data.sum(axis=1)/5
data
data.sum(axis=1)
Soumya 218.4
Chandan 278.4
Mukesh 301.2
Ashish 302.4
Sarat 300.0
dtype: float64
data[["Maths","English"]]
data[data>40]
data>40
#who scored the highest marks in each subject?
data.idxmax()
English Mukesh
Maths Chandan
Physics Mukesh
Chemistry Sarat
Biology Ashish
Average Ashish
dtype: object
data[data["Maths"]>40]["Maths"]
Chandan 74
Name: Maths, dtype: int32
#how many people have passed in maths
len(data[data["Maths"]>40]["Maths"])
1
#how many people have failed in maths
len(data[data["Maths"]<40]["Maths"])
4
#Maxmimum score in a subject
data.max()
English 70.0
Maths 74.0
Physics 86.0
Chemistry 94.0
Biology 48.0
Average 50.4
dtype: float64
data.max(axis=1)
Soumya 64.0
Chandan 74.0
Mukesh 86.0
Ashish 66.0
Sarat 94.0
dtype: float64
%matplotlib inline
data.plot.bar()
<matplotlib.axes._subplots.AxesSubplot at 0x199844e9748>
import jovian
jovian.commit()
[jovian] Saving notebook..