0% found this document useful (0 votes)
43 views3 pages

Python Pandas Worksheet

The document contains a worksheet with 12 questions about dataframes in Python. It provides sample code and data to work with for each question. Students are asked to write Python code to perform operations like creating dataframes, adding/removing columns, selecting rows/columns, and calculating values.

Uploaded by

Ahmadullah Arif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

Python Pandas Worksheet

The document contains a worksheet with 12 questions about dataframes in Python. It provides sample code and data to work with for each question. Students are asked to write Python code to perform operations like creating dataframes, adding/removing columns, selecting rows/columns, and calculating values.

Uploaded by

Ahmadullah Arif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

M.E.

S INDIAN SCHOOL, DOHA -QATAR


Worksheet-6 2024- 2025

Section :Boys’/Girls’ Date : 29/4/2024


Class & Div. :All Divisions Subject :IP
Lesson / Topic: Data Handling using Pandas – I (Dataframe)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

1. Write a Python code to generate the dataframe(MARKS) and display the result as whose mark is greater than 40.

Marks
Manish 45
Scott 34
Rhea 67

2.Find the output.


import pandas as pd
df1=pd.DataFrame([[10,20],[40,50]],columns=["A","B"])
df2=pd.DataFrame([[10,20],[40,50]],columns=["B","A"])
df3=df1+df2
print(df3)

3. Write the output:

import pandas as pd
S1 = pd.Series([1, 2, 3, 4], index = ['a', 'b','c','d'])
S2 = pd.Series([11, 22, 33, 44], index = ['a', 'bb','c','dd'])
D1 = pd.DataFrame({"Series1":S1,"Series2":S2})
print(D1)

4. Consider the given dataframe Product., Write the python code for the following:

Item Company Rupees


TV SAMSUNG 12000
TV VIDEOCON 10000
TV LG 15000
AC GENERAL 24000

a) To create the data frame Product for the above table.


b) To change the 2nd row as. (FRIDGE,SHARP,15000).
c) To display the price of LG TV.

5.Write the output:

import pandas as pd
d= [ {‘a’:10, ‘b’:20}, {‘a’:6, ‘b’:32, ‘c’:22}]
df1=pd.DataFrame(d, index= [‘x’, ‘y’], columns=[‘a’,’B’])
df2=pd. DataFrame (d, index= [‘x’, ‘y’], columns=[‘A’,’b’])
print(df1)
print(df2)

F 061, Rev 01, dtd 10th March 2020


6. Consider the dataframe car,and Write commands to :

Cartype CarName ParkingSlot Payment


A1 HatchBack i10 Block A 2000
A2 Sedan Ciaz Block B 2300
A3 MPV Omini Block D 2500
A4 SUV Scorpio Block C 3000

i. Add a new column ‘time’ after CarName column to the Dataframe.


ii. Display the first three columns.
iii. Add a new row with suitable values.
iv. Display the parking slot and payment of Sedan and MPV.
v. Remove the columns CarName and Payment.

7. Create the DataFrame with the data given and answer the questions from (a) to (e)

d = {'name': ['James', 'Anna', 'Janet', 'Yogi', 'Robin'],


'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai','Manchester'],
'age': [41, 28, 33, 34, 38],
'score': [88.0, 79.0, 81.0, 80.0, 68.0,]}
row_labels = [101, 102, 103, 104, 105]

a. Display the city of all the students.


b. Display the details of the students 102 to 105
c. Display the city in which Robin lives.
d.Display 1 to 3 rows and first 3 columns from the dataframe df.
e. To delete the data of Yogi.

8. Write a python code to create a dataframe Rank for the following data.

Name Marks Rank


Student1 Aisha 90.0 I
Student2 Amisha 82.0 II
Student3 Jai NaN NaN

9. Consider the following DataFrame, class.

Rollno Name Class Section CGPA Stream


St1 1 Aman IX E 8.7 Science
St2 2 Preeti X F 8.9 Arts
St3 3 Karthick IX D 9.2 Science
St4 4 Lakshay X A 9.4 Commerce
i. Add a new column ‘Gender’ after Name column to the Dataframe.
ii. Display the first three columns.
iii. Add a new student with values ( 5 , Mridula ,X, F , 9.8, Science)
iv. Display the name and stream of Preeti and karthick.
v. Remove the columns class and section.

F 061, Rev 01, dtd 10th March 2020


10. Mr. Summit, a data analyst has designed the DataFrame df that contains data about Computer
infrastructure with ‘S01’, ‘S02’, ‘S03’, ‘S04’, ‘S05, ‘S06’ as indexes shown below. Answer the following
school computers non-working working questions:
S01 MPS 80 10 70
S02 SFC 88 12 76
S03 JPS 25 4 21
S04 APS 45 6 39
S05 RLPS 90 15 75
S06 DPS 60 6 54

i) Predict the output of the following python statement:


A) df.shape B) df[2:4]

ii) Write Python statement to display the data of working column of indexes S03 to S05.
OR (Option for part ii only)
Write Python statement to compute and display the difference of data of computers column and
working column of the above given DataFrame.

11. Consider the following DataFrame, Class DF with row index St1,St2,St3,St4.

Rollno Name Class Section CGPA Stream


St1 1 Aman IX E 8.7 Science
St2 2 Preeti X F 8.9 Arts
St3 3 Kartikey IX D 9.2 Science
St4 4 Lakshay X A 9.4 Commerce

Based on the above dataframe answer the following:


A. Predict the output
i. ClassDF.index ii) ClassDF [ : : -2]

B. Write python statement to print Name,class and CGPA for Student St2 and St3
OR
Write a python Statement to print the name and class of students having CGPA 9.2.

12. Mr. Kapoor, a data analyst has designed the dataframe DF that contains data about Attendance and
number of classes of a week as shown below. Answer the following questions:

A. Predict the output of the following python statement:


a. print(DF[3: ]) b. print(DF.index)

B. Write Python statement to display the data of ‘No_of_classes’ column of indexes ‘Tuesday’ to ‘Thursday’
OR (for option B only)
Write python statement to calculate No_of_classes * Atten and display it as Total attendance in a day.

*************************************************************************************

F 061, Rev 01, dtd 10th March 2020

You might also like