Jovian
⭐️
Sign In
In [24]:
import numpy as np
import pandas as pd
In [2]:
np.random.rand(2)
Out[2]:
array([0.20770659, 0.82196949])
In [3]:
arr = np.random.rand(5,5)
In [4]:
np.random.randint(10,100,[5,5])
Out[4]:
array([[82, 96, 75, 71, 89],
       [31, 30, 51, 83, 41],
       [67, 42, 48, 97, 26],
       [72, 40, 98, 10, 51],
       [21, 27, 88, 40, 74]])
In [5]:
arr
Out[5]:
array([[0.16243367, 0.63110508, 0.42406086, 0.09012473, 0.06837255],
       [0.56793954, 0.42375577, 0.97094924, 0.51968206, 0.31538986],
       [0.81774209, 0.77636764, 0.0022875 , 0.97491083, 0.93901111],
       [0.68323422, 0.51012963, 0.24797004, 0.30985392, 0.9926488 ],
       [0.70169367, 0.27032417, 0.48104882, 0.2145747 , 0.13595081]])
In [6]:
arr = arr *100
In [7]:
arr
Out[7]:
array([[16.24336729, 63.11050793, 42.40608574,  9.01247328,  6.83725465],
       [56.79395379, 42.37557678, 97.09492415, 51.96820573, 31.53898618],
       [81.77420861, 77.63676411,  0.22874967, 97.49108347, 93.90111147],
       [68.32342248, 51.01296327, 24.79700361, 30.98539209, 99.26488036],
       [70.16936656, 27.03241742, 48.10488175, 21.45747028, 13.59508129]])
In [8]:
arr = arr.astype(int)
In [9]:
arr
Out[9]:
array([[16, 63, 42,  9,  6],
       [56, 42, 97, 51, 31],
       [81, 77,  0, 97, 93],
       [68, 51, 24, 30, 99],
       [70, 27, 48, 21, 13]])
In [10]:
pd.DataFrame(arr)
Out[10]:
In [11]:
students = []
subjects = []
In [12]:
sub = input("enter name of subject")
enter name of subjectk
In [13]:
sub
Out[13]:
'k'
In [14]:
for i in range(5):
    stu = input("enter name of subject")
    subjects.append(stu)
enter name of subjectMath enter name of subjectScience enter name of subjectSports enter name of subjectSocial Science enter name of subjectEnglish
In [15]:
subjects
Out[15]:
['Math', 'Science', 'Sports', 'Social Science', 'English']
In [16]:
for i in range(5):
    stu = input("enter name of students")
    students.append(stu)
enter name of studentsShibani enter name of studentsPriya enter name of studentsSangram enter name of studentsBishnupriya enter name of studentsSubhashree
In [17]:
students
Out[17]:
['Shibani', 'Priya', 'Sangram', 'Bishnupriya', 'Subhashree']
In [18]:
arr
Out[18]:
array([[16, 63, 42,  9,  6],
       [56, 42, 97, 51, 31],
       [81, 77,  0, 97, 93],
       [68, 51, 24, 30, 99],
       [70, 27, 48, 21, 13]])
In [26]:
data = pd.DataFrame(arr, columns=subjects, index=students)
In [27]:
data
Out[27]:

#Maximum score in a subject

In [62]:
data.max(axis=1)
Out[62]:
Shibani        63.0
Priya          97.0
Sangram        97.0
Bishnupriya    99.0
Subhashree     70.0
dtype: float64
In [29]:
data["Math"]
Out[29]:
Shibani        16
Priya          56
Sangram        81
Bishnupriya    68
Subhashree     70
Name: Math, dtype: int64
In [35]:
data.loc["Shibani"]
Out[35]:
Math              16
Science           63
Sports            42
Social Science     9
English            6
Name: Shibani, dtype: int64
In [39]:
data.sum(axis=1)/5
Out[39]:
Shibani        27.2
Priya          55.4
Sangram        69.6
Bishnupriya    54.4
Subhashree     35.8
dtype: float64
In [38]:
data.sum()
Out[38]:
Math              291
Science           260
Sports            211
Social Science    208
English           242
dtype: int64
In [41]:
data["Average"] = data.sum(axis=1)/5
In [42]:
data
Out[42]:
In [43]:
data.loc["Priya"]
Out[43]:
Math              56.0
Science           42.0
Sports            97.0
Social Science    51.0
English           31.0
Average           55.4
Name: Priya, dtype: float64
In [47]:
data.iloc[1:3]
Out[47]:
In [52]:
data[["Math","Science"]]
Out[52]:
In [53]:
data[data>40]
Out[53]:
In [54]:
data>40
Out[54]:
In [55]:
#who scored the highest marks in each subject? 
data.idxmax()
Out[55]:
Math                  Sangram
Science               Sangram
Sports                  Priya
Social Science        Sangram
English           Bishnupriya
Average               Sangram
dtype: object
In [59]:
#how many people have passed in math?
data[data["Math"]<40]["Math"]
Out[59]:
Shibani    16
Name: Math, dtype: int64
In [64]:
data.max(axis=1)
Out[64]:
Shibani        63.0
Priya          97.0
Sangram        97.0
Bishnupriya    99.0
Subhashree     70.0
dtype: float64
In [65]:
data
Out[65]:
In [66]:
%matplotlib inline
In [69]:
data.plot.bar()
Out[69]:
<matplotlib.axes._subplots.AxesSubplot at 0x11b44fc50>
Notebook Image
In [70]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: