Skip to main content

IP - DATAFRAME REVISION - 27 AUG

 

DATAFRAME REVISION

GRADE XII


(a) Write python statements to create a data frame “STAFF” for the following data.

           Name   Age  Designation

T100 YAMINI 35 PRINCIPAL

T101 DINESH 40 SYSTEM MANAGER

T102 SHYAM 50 TEACHER

T103 VINOD 45 ACCOUNTANT

T104 SYRIA 30 RECEPTIONIST

(b) Write the python code to rename the column designation to desig in the

dataframe created in the previous question.

(c) Add one more student‟s record permanently in the dataframe.

(d) Add one more column to store the fee details.

(e) Write python code to delete column fee of data frame permanently.

(f) Write python code to delete the 3rd and 5th rows from dataframe.

(g) Write a python code to display the name and designation of employees whose 

age more than 40 and less than 50.

(h) Change the designation of Shyam to Vice Principal

(i) Display the details of teachers having the index as T101, T103.


SOL:

Ans: (a) import pandas as pd

data={'name':['Yamini','Dinesh','Shyam','Vinod','Syria'],'Age':[35,40,50,45,30],'design

ation':['Principal','System Manager','Teacher','Accountant','Receptionist']}

staff=pd.DataFrame(data,index=['T100','T101','T102','T103','T104'])

print(staff)

(b)staff.rename(columns={'designation':'desig'})

Note: use inplace=True, if you want permanent renaming

(c)staff.loc['T105']=['Ram',15,'Student']

(d)staff['fees']=[6000,7000,4500,4600,4900,12000]

(e) staff.drop(columns='fees',inplace=True)

(f)staff.drop(df.index[[2,4]])

(g)staff.loc[(staff.Age>40)&(staff.Age<50),['name','designation']]

(h)staff.loc[staff.name=='Shyam','desig']='Vice Principal'

(i)staff.loc[['T101','T103']]


DATA ENTRY USING DATAFRAME

#

import pandas as pd

#eval() PARSES THE EXPRESSION PASSES TO IT AND RUN CODE WITH IN THE EXPRESSION

roll=eval(input("Enter the 3 rollnos:"))

name=eval(input("Enter the 3 Names:"))

marks=eval(input("Enter the 3 Marks:"))


d={"ROLLNO":roll,"NAME":name,"MARKS":marks}

df=pd.DataFrame(d)

print(df)

#sorting

#IN ACENDING ORDER

print("#"*50)

df=df.sort_values(by=['MARKS'])

print(df)

print("#"*50)

df=df.sort_values(by=['MARKS'],ascending=[False])

print(df)

'''


l=[['Alex',10],['bob',12],['Clark',13]]

data1=pd.DataFrame(l,columns=['NAME','AGE'])

print(data1)

#data1.iloc[1,1] = 4

data1.loc[2, 'AGE'] = 34

#data1.at[0,'Age']= 20


Comments

Popular posts from this blog

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

GRADE XII CS - VIVA QUESTIONS

  VIVA QUESTIONS GRADE XII CS Dear All Be thorough with your project and practical files, as the viva can be asked from anywhere. Stay calm, don’t get nervous, and be confident in front of the examiner. 1. Tell me about your project. 2. Which concepts you have used for your project? 3. What do you mean by front end and back end? How they are important in developing any such projects? 4  Mention the modules and built-in functions you have used in your project. 5. Which real world problems are solved by your project? 6. Explain the most important feature of your project. 7. Name a few mutable data types of python. Lists, Sets, and Dictionaries 8. Name a few immutable data types of python. Strings, Tuples, Numeric 9. Name ordered and unordered data type of python. Ordered – String, List, Tuples Unordred – Set, Dictionaries 10. What is the significance of a pass statement in python? pass is no operation python statement. This is used where python requires syntax but logic requires...