Consider,
data=pd.DataFrame({'names':['tom','sam',...],'email':['tom21@gmail.com','samdr@yahoo.com','jk21456@abc.com',..],'Firstweekscore':[],'secondweekscore:[]})
1.Write a function which will create a new column consisting of average of two scores
data['average']=(data['first_weekscore']+data['second_weekscore'])/2
2.List comprehension --> create another column which is consisting of scores 93 --> 96
week3=[i+3 for i in data['second_weekscore']] data['week3']=week3 print(data)
3.'gmail.com' -->regular expressions in pandas
4.Select rows which are having gmail address and also secondtestscore greater than 90
d=data[data['email'].str.contains('\w+@gmail.com')==True] v=d[d['second_weekscore']>90] for i in v['email']: print(i.split('@')[0])
5.Create a new column 'group' and randomly assign values as 1,2 and 3
from numpy import random l=random.randint(1,4, size=(4))
data['group']=l
6.Create a pivot table having means of first test scores,by group
table = pd.pivot_table(data=data,index=['group'],aggfunc=np.mean,values="first_weekscore") print(table)
Comments
Post a Comment