0% found this document useful (0 votes)
46 views

DataFrame Revision

Uploaded by

Rajitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

DataFrame Revision

Uploaded by

Rajitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Page 1 of 7

REVISION SHEET – NOVEMBER 2024


INFORMATICS PRACTICES
1) Shobit needs to create the following two series named ‘Eng’ and
‘Math’. Help him to create a DataFrame ‘mydata’ from the given series
‘Eng’ and ‘Math’.

2) Consider the code given below and answer the following question:
Ld=[{'a',10,'b':20},{'a':5,'b':10,'c':20}]
df=pd.DataFrame(Ld)
print(df)

i) Write the missing statement in the above code which will give error.
ii) How many columns will be there in the dataframe.

3) Write a python code to create a DataFrame with appropriate column


headings
from the list given below:
[[201,’Gurmeet’,95],[202,’Praveen’,89],[203,’Suman’,97],
[204.’Yogesh’,91]]

4) Consider the given DataFrame ‘Fees’:

Write suitable Python statements for the following:


i. Add a column called ‘Section’ with the following data:
[‘A’,’B’,’C’,’D’].
ii. Add a new Class Name named ‘IX' having price 1800 and Section
“B”.
iii. Remove the column ‘Section’.

5) Mr. Ankit is working in an organization as data analyst. He uses Python


Pandas and Matplotlib for the same. He got a dataset of the passengers
Page 2 of 7

for the year 2010 to 2012 for January, March and December. His
manager wants certain information from him, but he is facing some
problems. Help him by answering few questions given below:

A. Predict the output of the following python statement:


i. df.tail(3)
ii. df[‘Passenger’][[df.Passengers>50] ]
iii.Write Python statement to display the data of year column of indexes
1 to 3.
OR (Option for part iii only)
Write the Python code to rename the name of the column name is
‘mon_name’in
place of “Month” in the above Dataframe.

6) Complete the given Python code:


import pandas as pd
import numpy as np
Name = _________ .array([‘Anil’,’Sumit’,’Akhil’,’Ananya’])
___________ = __________ . DataFrame(____)
print(DF)

7) Create a DataFrame in Python from the given list:


[[‘Kavya’, 250],[‘Ananya’,150],[‘Malini’,185],[‘Raja’,320]]
Also give appropriate column headings as shown below:
Page 3 of 7

8) Consider the given DataFrame ‘ Stock’

Write suitable Python statements for the following:


i. Add a column called Special_Price with the following data:
[220,115,145,285].
ii. Add a new Stock of Name ‘NCDEX’ having Price as 280
iii. Remove the column Price

9) Ram designed the DataFrame df that contains the temperature of


different cities as shown below:

Answer the following Questions:


i. Predict the output of the following python statement:
a. Print(df.size)
b. Print(df[1:3])
ii. Delete the last row from the DataFrame.
iii. Write python statement to add a new city named ‘Calcutta’ having
Maxtemp 28, Mintemp 19, Avgtemp 24, Rainfall 20.1

10) The python code written below has syntactical errors. Rewrite the
correct code
and underline the corrections made.
IMPORT pandas as pd
df ={"name":["satish","rahul","arvind"],"exp(in months)":[14,41,31]}
df= pd.dataframe(df)
print(df)
11) Write a Python code to create a DataFrame with column headings
as (stu_id, name, class) and data labels as (1,4,5,6) from the list given
below:
L1=[[101,'Guru',10],[102,'Raj',9],[103,'Sam',12],[104,'Yuvraj',12]]

12) Consider the given DataFrame ‘Items’:


Page 4 of 7

Write suitable Python statements for the following:


i) Add a column called Sale_Price which is 10% decreased value of Price
ii) Add a new item named “Printer” having price 8000 and Quantity as
10.
iii) Remove the column Quantity

13) Consider the following DataFrame, Class DF with row index St1, St2,
St3, St4

Based on the above dataframe answer the following:


A. Predict the output
i. ClassDF.T ii. ClasDF [ : : -2]
B. Write python statement to print Name,class and CGPA for Student
St2 and St3
OR
write python Statement to print the name and class of students having
CGPA more than 9.0

14) The python code written below has syntactical errors. Rewrite the
correct code
and underline the corrections made.
import pandas as pt
data = {'Name': ['Ramesh Pillai', 'Priya Nair', 'Suresh Menon'], 'Age':
[28, 32, 26],
'City': ['Mcleodganj', 'Jalandhar', 'Sanchor']}
df = pd.DataFrame(data)
print(df.head)

15) You are tasked with creating a DataFrame to store information about
gaming apps available on various digital platforms. The DataFrame
should have three columns: Name, Genre, Type (Free or Paid), and
Downloads. To achieve this, you have the following data:
Page 5 of 7

Now create a dataframe with a dictionary of Series and index should be from
1 to 5.

16) Consider the given DataFrame ‘Anime’:

Write suitable Python statements for the following:


1. Add a row with the following data: [“Death
Note“,“Mystery“,37,2006].
2. Rename the column ‘Eps’ to ‘Episodes’ and ‘Year of Creation‘ to
‘Year‘.
3. Drop the column ‘Genre‘.

17) Riya, a Data Analyst working for a film studio, has created a
DataFrame named 'movie_revenue_df' to store the revenue data of
movies released by Viacom 18 in the year 2022. The DataFrame looks
like this:
Movie Revenue (in crores)
A. Gangubai Kathiawadi 125
B. The Kashmir Files 340
C. Bhediya 75
D. JugJugg Jiyo 250
E. Bachchhan Pandey 120

An intern is working with her and has a few doubts. As Riya is busy with
analysis work. You answer on her behalf.
(i) Predict the output of the following python statement:
a. print(movie_revenue_df[‘Revenue (in crores)’].dtypes)
b. print(movie_revenue_df.iloc[2,0])
Page 6 of 7

(ii) Delete the Second last row from the DataFrame.


(iii) Find out the total revenue.
OR (Option for part iii only)
Write Python statement to export the DataFrame to a CSV file named
“hit_movies_2022.csv” in the directory named ‘PMDB’ which is inside the
present working directory(PWD) of the project.

18) Answer the following questions based on the code given below : -
…………………….... # Statement 1
Ld=[{'a',10,'b':20},{'a':5,'b':10,'c':20}]
df=pd.DataFrame(Ld)
print(df)
i) Write the statement 1 in the above code.
ii) How many columns will be there in the dataframe.

19) Write a python code to create a DataFrame with appropriate column


headings from
the list given below:
[[201,’Gurmeet’,95],[202,’Praveen’,89],[203,’Suman’,97],
[204.’Yogesh’,91]]

20) Consider the given DataFrame ‘Fees’:

Write suitable Python statements for the following:


i. Add a column called ‘Section’ with the data: [‘A’,’B’,’C’,’D’]
ii. Add a new Class Name named ‘IX' having price 1800.
iii. Remove the column ‘Section’.

21) Assume a DataFrame df has following data of passengers for the


year 2010 to 2012 for January, March and December. Find output of the
following python statements given below: -
Page 7 of 7

==========

You might also like