0% found this document useful (0 votes)
6 views7 pages

Wa0004

The document contains a series of questions and exercises related to Python programming and the Pandas library, focusing on DataFrame and Series manipulation. It includes multiple-choice questions, coding tasks, and error correction exercises. The content is aimed at assessing knowledge and skills in using Pandas for data analysis in Python.

Uploaded by

atitbadayak2064
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)
6 views7 pages

Wa0004

The document contains a series of questions and exercises related to Python programming and the Pandas library, focusing on DataFrame and Series manipulation. It includes multiple-choice questions, coding tasks, and error correction exercises. The content is aimed at assessing knowledge and skills in using Pandas for data analysis in Python.

Uploaded by

atitbadayak2064
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/ 7

1.

Which of the following Python statements can be used to select a 1


column_name from a DataFrame df ?
A. df.getcolumn('column_name') (B) df['column_name']
(C) df.select('column_name') (D) df(column_name)

12. In a Pandas DataFrame, if the tail() function is used without specifying


the optional argument indicating the number of rows to display, what is
the default number of rows displayed, considering the DataFrame has 10
entries?
A. 0 (B) 1 (C) 4 (D) 5
 While creating a Series using a dictionary, the keys of the dictionary
become:
(A) Values of the Series (B) Indices of the Series
(C) Data type of the Series (D) Name of the Series

 Boolean indexing in Pandas DataFrame can be used for .


A. Creating a new DataFrame (B) Sorting data based on index labels
(C) Joining data using labels (D) Filtering data based on condition

 Assertion (A): We can add a new column in an existing DataFrame. 1


Reason (R): DataFrames are size mutable.

 What is a Series in Python Pandas? Also, give a suitable example to


support your answer.
IP-Pre board 1

A) Sneha is writing a Python program to create a DataFrame using


a list of dictionaries. However, her code contains some mistakes. Identify
the errors, rewrite the correct code, and underline the corrections made.

import Pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha", 'Age': 28}
data = [D1,D2,D3)
df = pd.Dataframe(data) print(df)

Ans:-
import pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha', 'Age': 28} data = [D1, D2, D3]
df = pd.DataFrame(data) print(df)

Changes Made :
i. Changed Pandas to pandas.
ii. Corrected mismatched string quotation marks
iii. Corrected the closing parenthesis in the list data.
iv. Changed Dataframe to DataFrame.
(1/2 mark for each correct correction and underlining)

OR
B) Complete the given Python code to get the required output (ignore
the dtype attribute) as

Output:
Tamil Nadu Chennai
Uttar Pradesh Lucknow
Manipur Imphal
Code:
import as pd
data = ['Chennai',' ','Imphal']
indx = ['Tamil Nadu','Uttar Pradesh','Manipur']
s = pd.Series( , index)
print( )
Ans :- import pandas as pd
data = ['Chennai', 'Lucknow', 'Imphal']
indx = ['Tamil Nadu','Uttar Pradesh’, ‘Manipur']
s = pd.Series(data, indx)
print(s)
(1/2 mark for each correct fill in the blank)
C) Write a Python program to create the following DataFrame using
a list of dictionaries.

Product Price
0 Laptop 60000
1 Desktop 45000
2 Monitor 15000
3 Tablet 30000

OR
B) Write a Python Program to create a Pandas Series as shown below
using a dictionary. Note that the left column indicates the indices
and the right column displays the data.

Russia Mosco
Hungary Budpest
Switzerland Burn

36. Consider the DataFrame df shown below. 5

Movie ID Title Year Rating


0 1 LAGAAN 2001 8.4
1 2 TAARE ZAMEEN PAR 2007 8.5
2 3 3 IDIOTS 2009 8.4
3 4 DANGAL 2016 8.4
4 5 ANDHADHUN 2018 8.3

Write Python statements for the DataFrame df to:


I. Print the first two rows of the DataFrame df.
II. Display titles of all the movies.
III. Remove the column rating.
IV. Display the data of the 'Title' column from indexes 2 to 4 (both included)
V. Rename the column name 'Title' to 'Name'.

Pre-Board2 -IP
 To display last five rows of a series object ‘S’,
you may write:
i. S.Head()
ii. S.Tail(5)
iii. S.Head(5)
iv. S.tail()
 Which of the following statement will import pandas library?
i. Import pandas as pd
ii. import Pandas as py
iii. import pandas as pd
iv. import panda as pd

 Which of the following can be used to specify the data while creating a
DataFrame?
i. Series
ii. List of Dictionaries
iii. Structured ndarray
iv. All of these

 Write a program to create a series object using a dictionary that stores the number of students
12D of your school.
Note: Assume four house names are Beas, Chenab, Ravi and Satluj having 18, 2, 20, 18
students respectively and pandas library has been imported as pd.

24. What will be the output of the following code:


>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print(A>45)
25. Carefully observe the following code:
import pandas as pd
Year1={'Q1':5000,'Q2':8000,'Q3':12000,'Q4': 18000}
Year2={'A' :13000,'B':14000,'C':12000}
totSales={1:Year1,2:Year2}
df=pd.DataFrame(totSalles)
print(df)

Answer the following:

i. List the index of the DataFrame df


ii. List the column names of Data Frame df.

 Write a Python code to create a Data Frame with appropriate column headings from
the list given below:
[[101,'Gurman',98],[102,'Rajveer',95],[103,'Samar' ,96],[104,'Yuvraj',88]]

 Consider the given DataFrame ‘Stock’:

Name Price
1. Nancy Drew 150
2. Hardy boys 180
3. Diary of a wimpy kid 225
4. Harry Potter 500

Write suitable Python statements for the following:


i. Add a column called Special_Price with the following data:
[135,150,200,440].
ii. Add a new book named ‘The Secret' having price 800.
iii. Remove the column Special_Price.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy