0% found this document useful (0 votes)
15 views11 pages

Pandas & Vis 2

The document consists of a series of questions and answers related to DataFrame operations in Python using Pandas. It covers topics such as indexing, data manipulation, handling missing values, and plotting with Matplotlib. The questions are structured to test knowledge on specific commands and functions used in data analysis and visualization.

Uploaded by

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

Pandas & Vis 2

The document consists of a series of questions and answers related to DataFrame operations in Python using Pandas. It covers topics such as indexing, data manipulation, handling missing values, and plotting with Matplotlib. The questions are structured to test knowledge on specific commands and functions used in data analysis and visualization.

Uploaded by

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

Case Study Based Question

iv. df.index()=["Air India","Indigo","Spicejet","Jet","Emirates"]

2. iii) df.index=["Air India","Indigo","Spicejet","Jet","Emirates"]


3.

Q-2 Consider the following DataFrame df

Roll No. Name UT1 UT2 UT3 UT4


1 Prerna Singh 24 24 20 22
2 Manish Arora 18 17 19 22
3 TanishGoel 20 22 18 24
4 Falguni Jain 22 20 24 20
5 KanikaBhatnagar 15 20 18 22
6 Ramandeep Kaur 20 15 22 24

1. Write down the command that will give output:


rollno 6
name TanishGoel
UT1 24
UT2 24
UT3 24
UT4

a. print(df.max)
b. print(df.max())
c. print(df.max(axis=1))
d. print(df.max, axis=1)

2. The teacher needs to know the marks scored by the student with roll number.Help her to identify the
correct set of statement/s from the given options
a.
print(df1)
b. df1=df[rollno==4]
print(df1)
c . df1=df[df.rollno=4]
print(df1)
d. df1=df[df.rollno==4]
print(df1)
3. Which of the following statement/s will give the exact number of values ineach column of the
dataframe?
i) print(df.count())
ii) print(df.count(0))
iii) print(df.count)
iv)
Choose the correct option:
a. both (i) and (ii)
b. only (ii)
c. (i), (ii) and (iii)
d. (i), (ii) and (iv)
4. Which of the following command will display the column labels of thedataframe?
i) print(df.columns())
ii) print(df.column())
iii) print(df.column)
iv) print(df.columns)
5. Ms. Sharma, the class teacher wants to add a new column

a)
b)
c)
d) Both (b) and (c) are correct

ANS:- 1. b. print(df.max())
2.
print(df1)
d. df1=df[df.rollno==4]
print(df1)
3. a. both (i) and (ii)
4. d.print(df.columns)
5.

Q-3Consider the DataFrame dfmks having some missing values(shown as NaN) as shown below:
A B C D
acct 99 94.0 92 97.0
eco 90 94.0 92 97.0
eng 95 89.0 91 89.0
ip 94 NaN 99 95.0
math 97 100.0 99 NaN

1) Which function will fill0 in place of NaN.


a.dfmks.fillna
b.dfmks.fillNaN(0)
c.dfmks.fillna(0)
d.dfmks.fillNaN
2) Which function will not select all the rows that have NaNvalues.
a.dfmks.drop(3,4)
b.dfmks.dropna()
c.dfmks.dropna(4,5)
d.dfmks.dropNaN()
A B C D
acct FALSE FALSE FALSE FALSE
eco FALSE FALSE FALSE FALSE
eng FALSE FALSE FALSE FALSE
ip FALSE TRUE FALSE FALSE
math FALSE FALSE FALSE TRUE

3) The above output will be produced by using:


a.dfmks.isnull()
b.dfmks.show(True,False)
c.dfmks.isnull(True,False)
d.dfmks.show(Boolean)
4.Select code to arrange data in ascending order of section A.
5.Which library is necessary to import for above DataFrame.
a. Import matplotlib
b. Import pandas
c. Import csv
d. Import dataframe

ANS:- 1. c.dfmks.fillna(0)
2. b.dfmks.dropna()
3. a.dfmks.isnull()
4.
5. b.import pandas

Q-4.Consider the following DataFrame df and answer any four questions


Fruits Pulses Rice Wheat
Andhra p. 7830 931.0 7452.4 NaN
i)
Gujarat 11950 818.0 1930.0 2737.0
Kerala 113.1 1.7 2604.8 NaN
Punjab 7152 33. 11586.2 16440.5
Tripura 44.1 23.2 814.6 0.5
Uttar p. 140169.2 2184.4 13754.0 30056.0
Write down the command to find minimum value along the columns for each row.
a.df.min()
b.df.min(axis=1)
c.df.min(axis=0)
d.df.min(column)
ii) Which argument is used with max() function for only numeric values are used for calculation.
a.NaN=True
b.numerionly=True
c.skipna=True,numeric_value=True
d.skipNaN=True,number_value=True
iii) Select command to delete column wheat.
c.deldf.wheat
d.deldf[4]

iv) Which function is used to change the name of index.

v)
a.df.Fruits(7152)=9658
b.df.punjab[7152]=9658
]=9658

ANS:- i) b.df.min(axis=1)
ii) c.skipna=True,numeric_value=True
iii)
iv)
v)

Q-5 Consider the following DataFrame df and answer any four questions

Fruits Pulses Rice Wheat


Andhra p. 7830 931.0 7452.4 NaN
Gujarat 11950 818.0 1930.0 2737.0
Kerala 113.1 1.7 2604.8 NaN
Punjab 7152 33. 11586.2 16440.5
Tripura 44.1 23.2 814.6 0.5
Uttar p. 140169.2 2184.4 13754.0 30056.0

1. Add new row banglore with all columns value 1200


d.df.at.banglore=1200

2.The output:
11950 818.0
113.1 1.7
will be produced by:
a.df.show[1:3,0:2]
b.df.at[1:3,0:2]
c.df.loc[1:3,0:2]
d.df.iloc[1:3,0:2]
3.Which among given option produce output

Andhra p 3
gujarata 4
kerala 3
Punjab 4
Tripura 4
uttar p 4
a.df.count(axis=1)
b.df.count(axis=0)
c.df.count(rows)
d.df.count(columns)

ANS:- 1.
2. d.df.iloc[1:3,0:2]
3. b.df.T
4. c.median()
5. df.count(axis=1)

Q-6. Mr.Javed is working in a game software development industry and he was comparing the given chart
on the basis of the rating of the various games available on the play store.
He is trying to write a code to plot the
graph. Help him to fill in the blanks of the
code and get the desired output

import__________________________ #Statement 1
Games=["Subway Surfer","Temple Run","Candy Crush","Bottle Shot","Runner Best"]
Rating=[4.2,4.8,5.0,3.8,4.1] plt.______________(Games,Rating) #Statement 2

plt.xlabel("Games") plt.______________("Rating") #Statement 3

plt._______________ #Statement 4

i. Choose the right code from the following for statement 1.

i. matplotlib as plt

ii. pyplot as plt

iii. matplotlib.pyplot as plt

iv. matplotlib.plt as pyplot

ANS:- (iii) matplotlib.pyplot as plt

. Identify the name of the function that should be used in statement 2 to plot the above graph.
i. line()
ii. bar()
iii. hist()
iv.barh()

ANS:- (ii) bar()


iii. Choose the correct option for the statement 3.
i. title("Rating")
ii. ytitle("Rating")
iii. ylabel("Rating")
iv. yaxis("Rating")
ANS:-

iv) Choose the right function/method from the following for the statement 4.
i. display()
ii. print()
iii. bar()
iv. show()

Answer: (iv) show()

v) In case Mr. Javed wants to change the above plot to the any other shape, which statement, should he
change.
i. Statement 1
ii. Statement 2
iii. Statement 3
iv. Statement 4

Answer: Statement 2

Q-7 Khushi is the event incharge in a school. One of her students gave her a suggestion to use Python
Pandas and Matplotlib for analysing and visualising the data, respectively. She has created a Data frame
Third prizes won by different houses in
various events.

Write Python commands to do the following:


i. Display the house names where the number of Second Prizes are in the range of 12 to 20.
a. df['Name'][(df['Second']>=12) and (df['Second']<=20)]

b. df[Name][(df['Second']>=12) & (df['Second']<=20)]

c. df['Name'][(df['Second']>=12) & (df['Second']<=20)]

d. df[(df['Second']>=12) & (df['Second']<=20)]

ANS: c. df['Name'][(df['Second']>=12) & (df['Second']<=20)]

ii. Display all the records in the reverse order.

a. print(df[::1])

b. print(df.iloc[::-1])

c. print(df[-1:]+df[:-1])

d. print(df.reverse())

ANS: b. print(df.iloc[::-1])

iii. Display the bottom 3 records.

a. df.last(3)

b. df.bottom(3)

c. df.next(3)

d. df.tail(3)

ANS: d. df.tail(3)

iv) Choose the correct output for the given statements:

x=df.columns[:1]

print(x)
a. 0

b. Name

c. First

d. Error

ANS:- b. Name

. Which command will give the output 24:

a. print(df.size)

b. print(df.shape)

c. print(df.index)

d. print(df.axes)

ANS:- a. df.size

You might also like