Jovian
⭐️
Sign In
In [1]:
import numpy as np
import pandas as pd
In [2]:
np.random.rand(2)
Out[2]:
array([0.78790637, 0.53467687])
In [3]:
arr = np.random.rand(5,5)
In [4]:
np.random.randint(10,100,[5,5])
Out[4]:
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]])
In [5]:
arr = np.random.rand(5,5)
In [6]:
arr = arr * 100
In [7]:
arr
Out[7]:
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]])
In [8]:
arr = arr.astype(int)
In [9]:
arr
Out[9]:
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]])
 
In [10]:
arr
Out[10]:
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]])
In [11]:
pd.DataFrame(arr)
Out[11]:
In [12]:
students = []
subjects = []
In [ ]:
 
enter name of subjectk
In [ ]:
 
In [19]:
students
Out[19]:
['Soumya', 'Chandan', 'Mukesh', 'Ashish', 'Sarat']
In [20]:
subjects
Out[20]:
['English', 'Maths', 'Physics', 'Chemistry', 'Biology']
In [ ]:
 
In [15]:
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
In [16]:
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
In [17]:
arr
Out[17]:
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]])
In [22]:
data = pd.DataFrame(arr, columns=subjects, index=students)
In [23]:
data
Out[23]:
In [24]:
data.loc["Mukesh"]
Out[24]:
English      70
Maths        25
Physics      86
Chemistry    47
Biology      23
Name: Mukesh, dtype: int32
In [25]:
data.iloc[1:3]
Out[25]:
In [26]:
data["Average"] = data.sum(axis=1)/5
In [27]:
data
Out[27]:
In [28]:
data.sum(axis=1)
Out[28]:
Soumya     218.4
Chandan    278.4
Mukesh     301.2
Ashish     302.4
Sarat      300.0
dtype: float64
In [30]:
data[["Maths","English"]]
Out[30]:
In [31]:
data[data>40]
Out[31]:
In [32]:
data>40
Out[32]:
In [33]:
#who scored the highest marks in each subject?
data.idxmax()
Out[33]:
English       Mukesh
Maths        Chandan
Physics       Mukesh
Chemistry      Sarat
Biology       Ashish
Average       Ashish
dtype: object
In [34]:
data[data["Maths"]>40]["Maths"]
Out[34]:
Chandan    74
Name: Maths, dtype: int32
In [35]:
#how many people have passed in maths
len(data[data["Maths"]>40]["Maths"])
Out[35]:
1
In [36]:
#how many people have failed in maths
len(data[data["Maths"]<40]["Maths"])
Out[36]:
4
In [38]:
#Maxmimum score in a subject
data.max()
Out[38]:
English      70.0
Maths        74.0
Physics      86.0
Chemistry    94.0
Biology      48.0
Average      50.4
dtype: float64
In [39]:
data.max(axis=1)
Out[39]:
Soumya     64.0
Chandan    74.0
Mukesh     86.0
Ashish     66.0
Sarat      94.0
dtype: float64
In [40]:
%matplotlib inline
In [41]:
data.plot.bar()
Out[41]:
<matplotlib.axes._subplots.AxesSubplot at 0x199844e9748>
Notebook Image
In [42]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: