Python Class Questions
Python Class Questions
n=int(input("no. "))
fact=1
while n>0:
fact=fact*n
n=n-1
print("factorial is",fact)
Sum=0
count=0
while True:
n=input("enter no,:")
if n=="done":
break
n=float(n)
Sum=Sum+n
count=count+1
print("total",Sum)
print("count",count)
print("avg",Sum/count)
n=0
m=0
if p==5601:
input("Type of account")
else:
while n<3:
input("re enter")
n=n+1
a=int(input("amt to be withdrwan"))
else:
while m<7:
m=m+1
print("try later")
sir
#ATM Problem
password = 1234
count = 1
count2 = 1
passw = int(input("Enter your password: "))
if passw != password:
while passw != password:
if count == 3:
print("Your card is blocked")
break
print("Incorrect Password")
passw = int(input("Enter your passowrd again: "))
count = count + 1
if passw == password:
amount = int( input("Please enter your transaction amount"))
if amount > 20000 or amount % 500 != 0:
while amount > 20000 or amount % 500 != 0:
if count2 == 5:
print("Try after some time")
break
amount = int( input("Please enter your transaction amount again: "))
count2 = count2 + 1
if amount < 20000 and amount % 500 == 0:
print("Please collect your cash")
print("Thank you for visiting the branch")
QUESTION
n=-1
while n<6:
n=n+1
if n==3 or n==6:
continue
print(n)
QUESTION
Write a python programme that returns square root of perfect square number.
perfect square = 1, 4, 9, 16, 25, 36, ...
You are required to do this using while. Do not use num ** 0.5 to directly get
square root. Further, check your programme for very large number like
100000000, and compare your computation time using num ** 0.5 or
math.sqrt. If number is not a perfect square, then your programme should
return the message, “Number is not a perfect square”.
Input = 0, 10, 100, 101, 100000000
sol method 1
while error != 0:
sqrt = sqrt + 1
if( sqrt * sqrt == num):
print(sqrt)
break
error = num - sqrt * sqrt
if sqrt * sqrt > num:
print("number is not a perfect square")
break
sol method 2
n=int(input("enter no."))
s=-1
a=1
while n>=s*s:
s=s+1
if n==s*s:
print(s)
break
if n<s*s:
print("not a perfect square")
break
if n==0:
print(a)
Write a python programme that returns square root of perfect square number. Include check for
followings:
You are required to do this using while. Do not use num ** 0.5 to directly get square root.
Further, check your programme for very large number like 100000000, and compare your
computation time using num ** 0.5 or math.sqrt. If number is not a perfect square, then
your programme should return the message, “Number is not a perfect square”.
n=float(input("enter no."))
s=-1
a=1
while n>=s*s:
s=s+1
if n==s*s:
print(s)
break
if n<s*s:
break
if n==0:
print(a)
if n<0:
if n-int(n)!=0:
other way..
sqrt = 0
while error != 0:
sqrt = sqrt + 1
print(sqrt)
break
break
if error>0.000001:
print(sqt)
break
ERRORS
#Version 2
print("Incorrect version 2.0")
num = input("Enter positive integer: ")
num = float(num)
if(num < 0) :
print("Number should be positive")
elif int(num) - num != 0 :
print("Please enter positive integer")
else:
sqrt = 0
error = sqrt * sqrt - num
while abs(error) != 0:
if (sqrt * sqrt) > num:
print("Number is not perfect square")
break
if (sqrt * sqrt) - num == 0:
print("The square root of", num, "is ",sqrt)
break
sqrt = sqrt + 1
error = sqrt * sqrt - num
#still not working
#Version 3
print(""Version 3.0-Incorrect")
num = input("Enter positive integer: ")
num = float(num)
if(num < 0) :
print("Number should be positive")
elif int(num) - num != 0 :
print("Please enter positive integer")
else:
sqrt = 0
error = sqrt * sqrt - num
while abs(error) != 0:
sqrt = sqrt + 1
error = sqrt * sqrt - num
if (sqrt **sqrt) > num:
print("Number is not perfect square")
break
if (sqrt * sqrt) - num == 0:
print("The square root of", num, "is ",sqrt)
break
sol
2
print("Incorrect version 2.0")
num = float(num)
if(num < 0) :
else:
sqrt = 0
while abs(error) != 0:
sqrt = sqrt + 1
break
break
sqrt = sqrt + 1
rbi, sebi,prowess, bloomberg, moneycontrol. com, amfi website, BSE, NSE websites, wallstreet journal, IMF news
survey, reports of planning commission
1
print("Version 1: Incorrect")
num = float(num)
if(num < 0) :
else:
sqrt = 0
while abs(error) != 0:
sqrt = sqrt + 1
break
break
sqrt = sqrt + 1
num = float(num)
if(num < 0) :
else:
sqrt = 0
while abs(error) != 0:
sqrt = sqrt + 1
break
break
##Find the sum of all the positive numbers entered by the user. As soon
as the user enters a negative number, stop taking in any further input from
the user and display the sum .
s=0
while True: (iska mtlb system hmse baar baar puche input tabhi while ke
if n=="done": ab ye kaise dala isko hmne baad mei float mei bhi convert kiya hai
break aur tabhi input wale fun mei input hi hai not combined with int.
n=float(n)
if n<0:
break
s=s+n
print("sum",s)
seq=range(1,n+1)
total=0
for i in seq:
total=total+(1/i)**3
print(total)
gap=" "
for m in c:
print(gap,m)
gap=gap+" "
@no of vowels
name = input("Enter your name")
nvowels = 0
v = "aeioUAEIOU"
for i in name:
if i in v:
s", nvowels)
def endswith():
ln = len(find)
if word[-1:-ln-1:-1][::-1] == find:
return(True)
else:
return(False)
result=""
for i in n:
if i != " ":
result=result+i
print(result)
new problem @2
def numrem():
b="0123456789"
c=a.find(".")
result=a[:c+1:1]
str=""
for i in a[c+1:len(a)+1]:
if i in b:
continue
str+=i
result+=str
return(result)
3 a=["ahubhae","aarte","anmaye"]
x=0
for i in a:
if i[0] == "a" and i[-1] == "e":
x=x+1
print(x)
print(count)
LIST
a= range(12,101)
for x in a:
print(x)
a=range(1,201)
result=[]
for i in a:
if i%7==0 or i%11==0:
result.append(i)
print(i)
a=[]
for i in ls:
if i not in a:
a.append(i)
print(i)
nd=[]
for i in a:
if a.count(i)==1 :
nd.append(i)
print(nd)
@ even highest
ls=[1,2,2,1,3,4,6,7,9,10,1,6]
ls.sort()
b=[]
for i in ls:
if i%2==0:
b.append(i)
#The record of a student (Name, Roll No., Marks in five subjects and percentage of marks) is
# stRecord = ['Raman','A-36',[56,98,99,72,69],
# 78.8]
#Write Python statements to retrieve the following information from the list stRecord.
# ‘Raman’ to ‘Raghav’
ans
@@sir wala
even = []
for i in a:
if i % 2 == 0:
even.append(i)
if len(even) == 0:
else:
print(max(even))
/\/\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
tuple
a=1
tup=()
while a<=n:
a=a+1
tup=tup+(b,)
print(tup)
a = tuple()
a = a + (t,)
print(a)
a=input("enter mixdottext")
p=a.find(".")
sud=a[:p+1]
sad=a[p+1:]
sadwn=""
for i in sad:
if i not in "1,2,3,4,5,6,7,8,9":
sadwn=sadwn+i
return(sad + sadwn)
a=input("enter text")
q=""
for i in a:
if i not in "!,@,,#,$,%,^,&,*" :
q=q+i
print(q)
dict
b = [18,19,20,20,20]
d={}
r=range(0,len(a))
for i in r:
d[a[i]]= b[i]
print(d)
d={"s":"t","g":"d","p":"p"}
a= []
b= []
for i in d:
a.append(i)
b.append(d[i])
print(a)
print(b)
d.keys()
d.values()
d={"s":"t","g":"d","p":"p"}
l=list(d.values())
li=list(d.keys())
n= input("enter calue...")
a=li[l.index(n)]
print(a)
i = i.lower()
for x in i:
if x in "aeiou":
count_dummy += 1
break
if count_dummy == 0:
count_con += 1
count_dummy=0
print(count_con)
import numpy as np
import pandas as pd
q2@
import math
def correlationCoefficient(ls1,ls2) :
sum_X = 0
sum_Y = 0
sum_XY = 0
squareSum_X = 0
squareSum_Y = 0
i=0
while i < n :
i=i+1
return corr
ls1 = []
n = int(input("Enter number of elements you want : "))
ls1.append(ele)
print(ls1)
ls2 = []
ls2.append(el)
print(ls2)
if n==m:
else:
import numpy as np
import math as m
X=np.array(range(0,11))
#P(X=x)=ncx*p^x*(1-p)^(n-x)
a=[]
for i in X :
a.append(m.comb(10,i)*(0.5**i)*(0.5**(10-i)))
a=np.array(a)
(10 - X))
.......................................
import math as m
>>> X=np.array(range(0,11))
>>> for i in X :
print(m.comb(10,i)*(0.5**i)*(0.5**(10-i)))
>>> m
>>> a[[2,2,2,2]]
a[[2,2,2,2]]
>>> b=a[[2,2,2,2]]
b=a[[2,2,2,2]]
>>> a=[[2,2,2,2]]
>>> a
[[2, 2, 2, 2]]
>>> a[2]
a[2]
>>> a=array([2,4,8,10,23,45])
a=array([2,4,8,10,23,45])
>>> a=np.array([2,4,8,10,23,45])
>>> a=np.array([2,4,8,10,23,45])
>>> a
>>> a*2
array([ 4, 8, 16, 20, 46, 90])
>>> a>5
>>> T=True
>>> F=False
>>> a[[T,F,F,T,T,F]]
>>> a[1:]
>>> a[1::1]
>>> a[1::2]
>>>
>>>
>>>
>>> a
>>> a[a>5]
>>> a[a<20]
array([ 2, 4, 8, 10])
>>> a[[a<20]]
array([ 2, 4, 8, 10])
>>> a
>>> a=a%2==0
>>> a
>>> a[a%2==0]
array([False, False])
>>> a
>>> a
>>> a[a%2=0]
>>> a[a%2==0]
array([ 2, 4, 8, 10])
>>> a[a%2==1]
array([23, 45])
>>> a[8<a<20]
a[8<a<20]
ValueError: The truth value of an array with more than one element
is ambiguous. Use a.any() or a.all()
>>> a[::2]
array([ 2, 8, 23])
>>> a[a>8]
>>> a[a<20]
array([ 2, 4, 8, 10])
>>> b=a[a>8]
>>> b
>>> b[b<20]
array([10])
>>> lm=np.array([[1,2,3],[2,3,4],[3,4,5]])
>>> lm
array([[1, 2, 3],
[2, 3, 4],
[3, 4, 5]])
>>> lm.ndim
>>> lm.shape
(3, 3)
>>> lm.shape=(4,3)
lm.shape=(4,3)
>>> lm=np.array([[1,2,3],[2,3,4]])
>>> lm
array([[1, 2, 3],
[2, 3, 4]])
>>> lm.shape=(3,2)
>>> lm
array([[1, 2],
[3, 2],
[3, 4]])
>>>
>>> lm
array([[1, 2],
[3, 2],
[3, 4]])
>>> lm[1,1]
>>> lm[[0,1],2]
lm[[0,1],2]
>>> lm=np.array([[1,2,3],[2,3,4],[3,4,5]])
>>> lm
array([[1, 2, 3],
[2, 3, 4],
[3, 4, 5]])
>>> lm[[0,1],2]
array([3, 4])
>>> lm[[1,2],0]
array([2, 3])
>>> lm[2,2]
>>> lm[0,0]
>>> lm[1,[0,1]]
array([2, 3])
>>> lm[[0,1]]
array([[1, 2, 3],
[2, 3, 4]])
array([[1, 2],
[2, 3],
[3, 4]])
>>> lm[[0,1],:]
array([[1, 2, 3],
[2, 3, 4]])
>>> lm[[0,0,2,2],[0,2,0,2]]
array([1, 3, 3, 5])
>>> #0,2
>>> #2,0
>>> #2,2
PANDAS
>>> b=pd.Series(data=[1,2,3,4,5],dtype=float)
>>> b
0 1.0
1 2.0
2 3.0
3 4.0
4 5.0
dtype: float64
>>>
IQ=pd.Series(data=[1,2,3,4,5],index=["yoyo","ravi","wwwww","aaaa"
,"zzzzz"])
>>> IQ
yoyo 1
ravi 2
wwwww 3
aaaa 4
zzzzz 5
dtype: int64
>>> IQ["aaaa"]
>>> IQ*2
yoyo 2
ravi 4
wwwww 6
aaaa 8
zzzzz 10
dtype: int64
>>> IQ["ravi"]
>>> IQ["ustaad"]=100
>>> IQ
yoyo 1
ravi 2
wwwww 3
aaaa 4
zzzzz 5
ustaad 100
dtype: int64
>>> data={"NAME":["ravi","shyam","ganu"],"AGE":
[18,19,20],"CLASS":["12th","1st yr","2nd yr"]}
>>> type(data)
<class 'dict'>
>>> df=pd.DataFrame(data=data)
>>> df
1 shyam 19 1st yr
2 ganu 20 2nd yr
>>>
>>>
IQ=pd.DataFrame(data=[1,2,3,4,5],index=["yoyo","ravi","wwwww","
aaaa","zzzzz"])
>>> IQ
yoyo 1
ravi 2
wwwww 3
aaaa 4
zzzzz 5
>>>
IQ=pd.Series(data=[1,2,3,4,5],index=["yoyo","ravi","wwwww","aaaa"
,"zzzzz"],columns=["IQ LEVEL"])
IQ=pd.Series(data=[1,2,3,4,5],index=["yoyo","ravi","wwwww","aaaa"
,"zzzzz"],columns=["IQ LEVEL"])
TypeError: __init__() got an unexpected keyword argument
'columns'
>>> data={"NAME":
["AVI","JAPSAHEJ","LAKSH","SUKRITI","CHETNA"],"GENDER":
["MALE","MALE","MALE","FEMALE","FEMALE"],"AGE":
[21,17,13,8,13],"MARKS":[67,34,78,55,92]}
>>> data
>>> datapd.DataFrame(data=data)
datapd.DataFrame(data=data)
>>> data=pd.DataFrame(data=data)
>>> data
0 AVI MALE 21 67
1 JAPSAHEJ MALE 17 34
2 LAKSH MALE 13 78
3 SUKRITI FEMALE 8 55
4 CHETNA FEMALE 13 92
>>> data=pd.DataFrame(data=data)datapd.DataFrame(data=data)
>>> data=pd.DataFrame(data=data,columns=["sream"])
>>> data
sream
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
>>>
data=pd.DataFrame(data=data,columns=["sream":,"bcom","bcom","
bcom","bcom","bbe"])
>>>
data=pd.DataFrame(data=data,columns=["bcom","bcom","bcom","b
com","bbe"])
>>> data
>>> data
>>> data={"NAME":
["AVI","JAPSAHEJ","LAKSH","SUKRITI","CHETNA"],"GENDER":
["MALE","MALE","MALE","FEMALE","FEMALE"],"AGE":
[21,17,13,8,13],"MARKS":[67,34,78,55,92]}
>>> data
>>>
data=pd.DataFrame(data=data,columns=["bcom","bcom","bcom","b
com","bbe"])
>>> data
Empty DataFrame
Index: []
>>> data={"NAME":
["AVI","JAPSAHEJ","LAKSH","SUKRITI","CHETNA"],"GENDER":
["MALE","MALE","MALE","FEMALE","FEMALE"],"AGE":
[21,17,13,8,13],"MARKS":[67,34,78,55,92]}
>>> ab={"NAME":
["AVI","JAPSAHEJ","LAKSH","SUKRITI","CHETNA"],"GENDER":
["MALE","MALE","MALE","FEMALE","FEMALE"],"AGE":
[21,17,13,8,13],"MARKS":[67,34,78,55,92]}
>>> data=pd.DataFrame(data=ab)
>>> data
0 AVI MALE 21 67
1 JAPSAHEJ MALE 17 34
2 LAKSH MALE 13 78
3 SUKRITI FEMALE 8 55
4 CHETNA FEMALE 13 92
>>> ab["GENDER"]
>>> ab["GENDER","MARKS"]
ab["GENDER","MARKS"]
>>> ab[["GENDER","MARKS"]]
ab[["GENDER","MARKS"]]
>>> ab["GENDER","MARKS"]
ab["GENDER","MARKS"]
>>> ab["course"]
ab["course"]
KeyError: 'course'
>>> ab["course":1,2,3,4,4]
ab["course":1,2,3,4,4]
TypeError: unhashable type: 'slice'
>>> data={"NAME":
["AVI","JAPSAHEJ","LAKSH","SUKRITI","CHETNA"],"GENDER":
["MALE","MALE","MALE","FEMALE","FEMALE"],"AGE":
[21,17,13,8,13],"MARKS":[67,34,78,55,92]}
>>> ab={"NAME":
["AVI","JAPSAHEJ","LAKSH","SUKRITI","CHETNA"],"GENDER":
["MALE","MALE","MALE","FEMALE","FEMALE"],"AGE":
[21,17,13,8,13],"MARKS":[67,34,78,55,92]}
>>> data=pd.DataFrame(data=ab)
>>> data
0 AVI MALE 21 67
1 JAPSAHEJ MALE 17 34
2 LAKSH MALE 13 78
3 SUKRITI FEMALE 8 55
4 CHETNA FEMALE 13 92
>>> ab["course":1,2,3,4,5]
ab["course":1,2,3,4,5]
>>> ab["course":"1","2","3","4","5"]
Traceback (most recent call last):
ab["course":"1","2","3","4","5"]
>>> ab["course"]=[1,2,3,4,5]
>>> data
0 AVI MALE 21 67
1 JAPSAHEJ MALE 17 34
2 LAKSH MALE 13 78
3 SUKRITI FEMALE 8 55
4 CHETNA FEMALE 13 92
>>> ab
>>> data=pd.DataFrame(data=ab)
>>> data
0 AVI MALE 21 67 1
1 JAPSAHEJ MALE 17 34 2
2 LAKSH MALE 13 78 3
3 SUKRITI FEMALE 8 55 4
4 CHETNA FEMALE 13 92 5
>>> ab["AGE"]
>>> data["AGE"]
0 21
1 17
2 13
3 8
4 13
>>> data["AGE"]+data["MARKS"]
0 88
1 51
2 91
3 63
4 105
dtype: int64
>>> ab.iloc(2)
ab.iloc(2)
>>> ab.iloc[2]
ab.iloc[2]
>>> data.iloc[2]
NAME LAKSH
GENDER MALE
AGE 13
MARKS 78
course 3
>>> data[data["GENDER"]=="MALE"]
0 AVI MALE 21 67 1
1 JAPSAHEJ MALE 17 34 2
2 LAKSH MALE 13 78 3
>>>
#FURTHER PANDAS
>>>
>>> marks
0 1 Ravi 5 2
1 2 Shavi 6 10
2 3 Kavi 9 5
3 4 Savi 3 9
4 5 Mavi 4 8
5 6 Tavi 6 10
6 7 Ravi 6 4
7 8 Ravi 8 6
8 9 Shavi 7 7
9 10 Kavi 9 8
>>> marks[marks["NAME"]=="A"]
Empty DataFrame
Index: []
>>> marks[marks["NAME"]=="R"]
Empty DataFrame
Index: []
>>> marks[marks["NAME"]=="S"]
Empty DataFrame
Index: []
>>> marks.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10 entries, 0 to 9
>>> marks[marks["NAME"]=="Ravi"]
0 1 Ravi 5 2
6 7 Ravi 6 4
7 8 Ravi 8 6
>>> marks[marks["ASSIGNMENT"]>5]
1 2 Shavi 6 10
2 3 Kavi 9 5
5 6 Tavi 6 10
6 7 Ravi 6 4
7 8 Ravi 8 6
8 9 Shavi 7 7
9 10 Kavi 9 8
>>> marks[marks["ASSIGNMENT"]==10]
Empty DataFrame
>>> marks[marks["TEST"]==10]
1 2 Shavi 6 10
5 6 Tavi 6 10
>>> marks
0 1 Ravi 5 2
1 2 Shavi 6 10
2 3 Kavi 9 5
3 4 Savi 3 9
4 5 Mavi 4 8
5 6 Tavi 6 10
6 7 Ravi 6 4
7 8 Ravi 8 6
8 9 Shavi 7 7
9 10 Kavi 9 8
>>> #if by chance u put wrong data then how to edit that particular
value
>>> marks.iloc[0,3]
>>> ##or
>>> marks["TEST"]
0 2
1 10
2 5
3 9
4 8
5 10
6 4
7 6
8 7
9 8
>>> marks["TEST"][0]
>>> marks.iloc[0,3]=10
>>> marks
0 1 Ravi 5 10
1 2 Shavi 6 10
2 3 Kavi 9 5
3 4 Savi 3 9
4 5 Mavi 4 8
5 6 Tavi 6 10
6 7 Ravi 6 4
7 8 Ravi 8 6
8 9 Shavi 7 7
9 10 Kavi 9 8
>>>
>>>
>>> asg=marks["ASSIGNMENT"]
>>> asg
0 5
1 6
2 9
3 3
4 4
5 6
6 6
7 8
8 7
9 9
Name: ASSIGNMENT, dtype: int64
>>> tst=marks["TEST"]
>>> tst
0 10
1 10
2 5
3 9
4 8
5 10
6 4
7 6
8 7
9 8
>>> b=asg+tst
>>> b
0 15
1 16
2 14
3 12
4 12
5 16
6 10
7 14
8 14
9 17
dtype: int64
>>> marks["b"]
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-
32\lib\site-packages\pandas\core\indexes\base.py", line 2895, in
get_loc
return self._engine.get_loc(casted_key)
KeyError: 'b'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
marks["b"]
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-
32\lib\site-packages\pandas\core\frame.py", line 2906, in
__getitem__
indexer = self.columns.get_loc(key)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-
32\lib\site-packages\pandas\core\indexes\base.py", line 2897, in
get_loc
KeyError: 'b'
>>> marks[b]
marks[b]
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-
32\lib\site-packages\pandas\core\frame.py", line 2912, in
__getitem__
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-
32\lib\site-packages\pandas\core\indexing.py", line 1298, in
_validate_read_indexer
KeyError: "None of [Int64Index([15, 16, 14, 12, 12, 16, 10, 14, 14, 17],
dtype='int64')] are in the [columns]"
>>> marks["TOTAL"]=marks["ASSIGNMENT"]+marks["TEST"]
>>> marks
0 1 Ravi 5 10 15
1 2 Shavi 6 10 16
2 3 Kavi 9 5 14
3 4 Savi 3 9 12
4 5 Mavi 4 8 12
5 6 Tavi 6 10 16
6 7 Ravi 6 4 10
7 8 Ravi 8 6 14
8 9 Shavi 7 7 14
9 10 Kavi 9 8 17
>>> marks["TOTAL"]>10
0 True
1 True
2 True
3 True
4 True
5 True
6 False
7 True
8 True
9 True
>>> marks[marks["TOTAL"]>10]
0 1 Ravi 5 10 15
1 2 Shavi 6 10 16
2 3 Kavi 9 5 14
3 4 Savi 3 9 12
4 5 Mavi 4 8 12
5 6 Tavi 6 10 16
7 8 Ravi 8 6 14
8 9 Shavi 7 7 14
9 10 Kavi 9 8 17
0 1 Ravi 5 10 15
7 8 Ravi 8 6 14
>>> marks.sort_values(by="TOTAL")
6 7 Ravi 6 4 10
3 4 Savi 3 9 12
4 5 Mavi 4 8 12
2 3 Kavi 9 5 14
7 8 Ravi 8 6 14
8 9 Shavi 7 7 14
0 1 Ravi 5 10 15
1 2 Shavi 6 10 16
5 6 Tavi 6 10 16
9 10 Kavi 9 8 17
>>> marks.sort_values(by="TOTAL",ascending=False)
1 2 Shavi 6 10 16
5 6 Tavi 6 10 16
0 1 Ravi 5 10 15
2 3 Kavi 9 5 14
7 8 Ravi 8 6 14
8 9 Shavi 7 7 14
3 4 Savi 3 9 12
4 5 Mavi 4 8 12
6 7 Ravi 6 4 10
>>> marks.sort_values(by="TOTAL",inplace=True)
>>> marks
6 7 Ravi 6 4 10
3 4 Savi 3 9 12
4 5 Mavi 4 8 12
2 3 Kavi 9 5 14
7 8 Ravi 8 6 14
8 9 Shavi 7 7 14
0 1 Ravi 5 10 15
1 2 Shavi 6 10 16
5 6 Tavi 6 10 16
9 10 Kavi 9 8 17
>>> #bina variable diye wahi value assign karan is above question
>>>
6 7 Ravi 6 4 10
3 4 Savi 3 9 12
4 5 Mavi 4 8 12
2 3 Kavi 9 5 14
7 8 Ravi 8 6 14
8 9 Shavi 7 7 14
0 1 Ravi 5 10 15
1 2 Shavi 6 10 16
5 6 Tavi 6 10 16
9 10 Kavi 9 8 17
>>> marks.sort_values(by=["TOTAL","ROLL
NO."],ascending=[True,False])
6 7 Ravi 6 4 10
4 5 Mavi 4 8 12
3 4 Savi 3 9 12
8 9 Shavi 7 7 14
7 8 Ravi 8 6 14
2 3 Kavi 9 5 14
0 1 Ravi 5 10 15
5 6 Tavi 6 10 16
1 2 Shavi 6 10 16
9 10 Kavi 9 8 17
>>> marks.sort_values(by=["TOTAL","ROLL
NO."],ascending=[True,False],inplace=True)
>>> marks
6 7 Ravi 6 4 10
4 5 Mavi 4 8 12
3 4 Savi 3 9 12
8 9 Shavi 7 7 14
7 8 Ravi 8 6 14
2 3 Kavi 9 5 14
0 1 Ravi 5 10 15
5 6 Tavi 6 10 16
1 2 Shavi 6 10 16
9 10 Kavi 9 8 17
>>> #above done is when something is coming twice thrice and we
want further conditions
>>>
>>>
>>> marks,head()
marks,head()
>>> marks.head()
6 7 Ravi 6 4 10
4 5 Mavi 4 8 12
3 4 Savi 3 9 12
8 9 Shavi 7 7 14
7 8 Ravi 8 6 14
>>> marks.tail(6)
7 8 Ravi 8 6 14
2 3 Kavi 9 5 14
0 1 Ravi 5 10 15
5 6 Tavi 6 10 16
1 2 Shavi 6 10 16
9 10 Kavi 9 8 17
>>> marks.mean()
ASSIGNMENT 6.3
TEST 7.7
TOTAL 14.0
dtype: float64
>>> marks.mean(axis=1)
6 6.75
4 7.25
3 7.00
8 9.25
7 9.00
2 7.75
0 7.75
5 9.50
1 8.50
9 11.00
dtype: float64
>>> marks[["TEST","ASSIGNMENT","TOTAL
SyntaxError: EOL while scanning string literal
>>> marks[["TEST","ASSIGNMENT","TOTAL"]]
6 4 6 10
4 8 4 12
3 9 3 12
8 7 7 14
7 6 8 14
2 5 9 14
0 10 5 15
5 10 6 16
1 10 6 16
9 8 9 17
>>> marks
6 7 Ravi 6 4 10
4 5 Mavi 4 8 12
3 4 Savi 3 9 12
8 9 Shavi 7 7 14
7 8 Ravi 8 6 14
2 3 Kavi 9 5 14
0 1 Ravi 5 10 15
5 6 Tavi 6 10 16
1 2 Shavi 6 10 16
9 10 Kavi 9 8 17
>>> marks[["TEST","ASSIGNMENT","TOTAL"]].mean(axis=1)
6 6.666667
4 8.000000
3 8.000000
8 9.333333
7 9.333333
2 9.333333
0 10.000000
5 10.666667
1 10.666667
9 11.333333
dtype: float64