Information Practices
Section A
1. A _________ is a two dimensional labeled data structure.
a. Series b.DataFrame c. List d. None
2. To delete a row, the parameter axis of function drop() is assigned the value.
a. 0 b.1 c.2 d.3
3. Which of the following is correct statement for creating empty series?(Assume that
pandas library is already import as pd)
a. ser=pd.Series(NaN) b. ser=pd.Series(None) c. ser=pd.series d.ser=pd.Series()
4.Which library is to be imported for creating DataFrame?
a. python b. pandas c. DataFrame d. random
5. The following code create DataFrame name ‘Df’ with ___________ columns.
Df.DataFrame([1,4,6,8,9])
a. 1 b. 2 c. 3 d.4
6. To display first three rows of series object ‘M’, you may write:
a. M.head() b. M.tail(3) c. M.head(3) d. M.Tail(3)
7. Assertion (A): DataFrame has both a row and column index.
Reasoning (R): A DataFrame is a two-dimensional labelled data structure like a
table of MySQL.
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
8. Assertion (A): To use the Pandas library in a Python program, one must import it.
Reasoning (R): The only alias name that can be used with the Pandas library is
pd.
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
9. Which of the following statement will import pandas library?
a. Import pandas as pd b. import Pandas as py
c. import pandas as pd d. import panda as pd
10. While creating a series using a dictionary, a key become:
a. Values of the Series b. Indices of the Series
c. Name of the Series d. Datatype of the Series
11. 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
12. State whether the following statement is True or False
Slicing can be used to extract a specific portion from a Pandas Series.
13. Which of the following Python statements is used to import data from a CSV file
into a Pandas DataFrame (Note: pd is an alias for pandas)?
a. pd.open_csv(‘filename.csv’) b. pd. read_csv("filename csv")
c. pd. load_csv('filename.csv') d. pd. import_csv('filename.csv')
14. CSV stands for:
a. Column Separated Value b. Class Separated Value
c. Comma Separated Value d. None of the above
15. In Python Pandas, while performing mathematical operations on series, index
matching is implemented and all missing values are filled in with default. by
a. NaN b.Blank c.Null d.Zero
16.Which of the following can be used to specify the data while creating a
DataFrame? a.Series b. List of Dictionaries c.Structured ndarray d.
All of these
17. _______ is used to present data in 2D graphics.
a. numpy b. Matplotlib c.pandas d.none of these
18. The ________attribute in a pandas Series returns the number of dimensions of
the underlying data.
a.size b. Shape c.count d. ndim
19. _________ method iterates over a DataFramerow wise,where each horizontal
subset is in form of(RowIndex ,series) where series contains all column values that
row - index
a. iterrows() b.iteritems() c. itercols() d.None of these
20. __________ used to transpose the DataFrame
a. T b. Transpose c.Trans d.Tpose
21. In DataFrame axis=1 is for
a. columns b. rows c. rows and columns d.None of these
Section B
22.What will be the output of the following code:
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print(A>45)
23.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(totSales)
print(df)
Answer the following:
i. List the index of the DataFrame df
ii. List the column names of DataFrame df.
24. Difference between Series and DataFrame.
Or
What is the purpose of loc and iloc in pandas
25. 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)
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( __________, indx)
print( __________ )
26. Write method of series in pandas.
Section C
29.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
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 Moscow
Hungary Budapest
Switerland Bern
30. Consider the given DataFrame Genre:
Type Code
0 Fiction F
1 Non Fiction NF
2 Drama D
3 Poetry P
Write suitable Python statements for the following:
i. Add a column called Num_Copies with the following data [300,290,450,760].
ii. Add a new genre of type 'Folk Tale' having code as "FT” and 600 number of
copies.
iii. Rename the column 'Code' to 'Book _Code’.
31. Write a python code to create series object using python sequence.
32. Write a python code to create the following series using numpy and dictionary
H1 54
H2 43
H3 87
H4 66
H5 59
Section D
33.Ekam, a Data Analyst with a multinational brand has designed the DataFrame If
that contains the four quarter's sales data of different stores as shown below:
Store Qri Qtr2 Qr3 Qr4
0 Storel 300 240 450 230
1 Store2 350 340 403 210
2 Store3 250 180 145 160
Answer the following questions
i. Predict the output of the following python statement:
a. print(df size)
b. print(df[1:3])
ii.Rewrite the statement to write python code to delete the last row from the
DataFrame and correct the columns as well.
iii. Write Python statement to add a new column Total_Sales which is the addition of
all the 4 quarter sales.
OR
(Option for part iii only)
Write Python statement to export the DataFrame to a CSV file named data.csv
stored at D: drive
34. Mr. Som, a data analyst, has designed the DataFrame df that contains data
about Computer Olympiad with ‘CO1’, ‘CO2’, ‘CO3’, ‘CO4’, ‘CO5’ as indexes shown
below. Answer the following questions:
School Tot_students Topper First_Running
C01 PPS 40 32 8
C02 JPS 30 18 12
C03 GPS 20 18 2
C04 MPS 18 10 8
C05 BPS 28 20 8
(A) Predict the output of the following python statement:
(i) df.shape
(ii) df[2:4]
(B) Write Python statement to display the data of Topper column of indexes CO2 to
CO4.
OR
(Option for part iii only)
Write Python statement to compute and display the difference of data of
Tot_students column and First_Runnerup column of the above given DataFrame.
Section E
35. import pandas as pd
data = {
'Student Name': ['Ravi', 'Priya', 'Rahul'],
'Age': [21, 20, 22],
'City': ['Mumbai', 'Delhi', 'Bangalore']
df = pd.DataFrame(data)
i. print( df.columns) ii. print(df.size) iii. print(df.empty)
iv. print(df.ndim) v. print(df.shape)
36. Creation DataFrame using following table:
Name Age Marks Subject
R1 Jaya 14 98 cs
R2 Bala 17 78 bio
R3 Krish 15 68 pe
R4 sakthi 15 65 ip
R5 abi 13 87 cs
37. Complete the missing Python code
import matplotlib.pyplot as _____________
x __________ [10, 20, 30, 40, 50]
y = [65, 98, 170, 220, 310 _______
plt.xlabel('Overs')
plt.__________('Runs Scored')
plt.title('Over wise Runs Scored \n India Vs England')
plt.plot(x,y)
plt.____________()