Python Pandas MCQ with Answer


Hello friends, in this post we are going to discuss about Python Pandas Multiple choice question | Python Pandas Question Answer | Python Pandas TCS Fresco Play Dumps | Python Pandas Fresco Play Question answer | Python Pandas Objective type question

51.Which of the following expression returns data of column B of data frame df, defined below?
Which of the following expression returns the data of column B in data frame df, defined below.
import pandas as pd
df = pd.DataFrame({‘A’:[34, 78, 54], ‘B’:[12, 67, 43]}, index=[‘r1’, ‘r2’, ‘r3’])

Answer : df.B

52.Which of the following expression returns the first two rows of df, defined below?
import pandas as pd
df = pd.DataFrame({‘A’:[34, 78, 54], ‘B’:[12, 67, 43]}, index=[‘r1’, ‘r2’, ‘r3’])

Answer : Both df[:2] and df.iloc[:2]

53.Which of the following expression returns last two rows of df, defined below?
import pandas as pd
df = pd.DataFrame({‘A’:[34, 78, 54], ‘B’:[12, 67, 43]}, index=[‘r1’, ‘r2’, ‘r3’])

Answer : df.loc[‘r2′:’r3’]

54.What does the expression df.loc[‘r4’] = [67, 78] do for the data frame df, defined below?
df = pd.DataFrame({‘A’:[34, 78, 54], ‘B’:[12, 67, 43]}, index=[‘r1’, ‘r2’, ‘r3’])

Answer : Add a new row

55.Which of the following method is used to read data from excel files?

Answer : read_excel

56.What does the expression d + pd.Timedelta(‘1 days 2 hours’) do to DatetimeIndex object d,
defined below? d = pd.date_range(’11-Sep-2017′, ’17-Sep-2017′, freq=’2D’)

Answer : Increases each datetime value by 1 day and 2 hours


57.Which of the following method is used to convert a list of dates like strings into datetime objects?

Answer : to_datetime

58.By default, missing values in any data set are read as ………..

Answer : NaN

59.Which of the following argument values are allowed for the method argument of fillna?

Answer : All the options

60.Conisder a data frame df with columns [‘A’, ‘B’, ‘C’, ‘D’] and rows [‘r1’, ‘r2’, ‘r3’]. Which of the following expression filters those rows whose column B values are greater than 45?

Answer : df[df.B > 45]

61.Consider a data frame df with 10 rows and index [ ‘r1’, ‘r2’, ‘r3’, ‘row4’, ‘row5’, ‘row6’, ‘r7’, ‘r8’, ‘r9’, ‘row10’]. What does the expression g = df.groupby(df.index.str.len()) do?

Answer : Data frames cannot be grouped by index values. Hence it results in Error.

62.What is the output of the following code?
import pandas as pd
s = pd.Series([89.2, 76.4, 98.2, 75.9], index=list(‘abcd’))
print(s[[‘c’, ‘a’]])

Answer : c 98.2 a 89.2 dtype: float64


Leave a Reply

Your email address will not be published. Required fields are marked *