Asitdubey
2 min readJul 29, 2022

Hope you have enjoyed my past series on 5 Question Series. In this article I am going to start the MCQs on basic Python, which contains 5 questions.

Q1. choose the incorrect option to get next week date from today?

  1. pd.to_datetime((datetime.today() + timedelta(days = 7)).date()).strftime(‘%d %B %Y’)
  2. pd.to_datetime(datetime.strptime(str(pd.to_datetime(‘today’).date()), ‘%Y-%m-%d’) + timedelta(days=7)).strftime(‘%d %B %Y’)
  3. (datetime.now() + timedelta(days=7)).strftime(‘%d %B %Y’)
  4. (datetime.today() + timedelta(days=7)).dt.date

Ans: d

Q2. choose the incorrect option for changing the day and hour from today’s datetime?

a) print(datetime.now().replace(day = 4, hour = 16))

b) (print(datetime.today().replace(day = 12, hour = 6))).dt.date

c) pd.to_datetime(‘today’).replace(day = 10, hour = 19)

d) pd.to_datetime(‘now’).replace(day = 10, hour = 19)

ans:b

Q3. ‘a’ is the series of random no. between some range. choose the correct option to change all the no. in the series in a string ‘python’ except the most repetitive no.?

a) a = pd.Series(np.random.randint(1,5,11))

a[~a.isin(a.value_counts().index[:1])] = ‘python’

b) a = pd.Series(np.random(1,5,11))

a[~a.isin(a.value_counts().index[:1])] = ‘python’

c) a = pd.Series(np.random.randint(1,5,11))

a[a.isin(a.value_counts().index[:1])] = ‘python’

d) a = pd.Series(np.random.randint(1:11:5))

a[a.isin(a.value_counts().index[:1])] = ‘python’

ans:a

Q4. from the given series: ‘movie’ and ‘rating’; choose the correct option to calculate the mean of ratings given to the movies?

movie = pd.Series(np.random.choice([‘Iron-Man’, ‘Spiderman’, ‘Deadpool’], 10)) rating = pd.Series(np.random.randint(1, 10, 10))

a) rating.groupby(movie).mean()

b) movie.groupby(rating).mean()

c) rating.groupby(movie).np.avg()

d) rating.groupby(‘movie’).mean()

ans :a

Q5.

# which is the correct option to plot the survival rate of ‘Pclass’ in titanic dataframe?

a) titanic.plot(‘Pclass’,’Survived’)

b) sns.barplot(‘Pclass’, ‘Survived’, data = titanic)

c) plt.bar(titanic, ‘Pclass’, ‘Survived’)

d) plt.bar(titanic[‘Pclass’],titanic[‘Survived’])

ans: b

Q6. choose the incorrect option to show the count of total survival and non-survival passengers in the dataframe ‘titanic’. Taking ‘Survived’ as 0 and ‘not_survived’ as 1?

survived = titanic[titanic[‘Survived’]==0]

not_survived = titanic[titanic[‘Survived’]==1]

a)print(“Survived: %i (%.1f%%)” % (len(survived), float(len(survived))/len(titanic)*100))

print(“Not_Survived: %i (%.1f%%)” % (len(not_survived), float(len(not_survived))/len(titanic)*100))

b)print(“Survived: %i (%.1f%%)” % (len(survived), (len(survived))/len(titanic)*100))

print(“Not_Survived: %i (%.1f%%)” % (len(not_survived), (len(not_survived))/len(titanic)*100))

c)print(“Survived: %i (%.1f)” % (len(survived), float(len(survived))/len(titanic)))

print(“Not_Survived: %i (%.1f)” % (len(not_survived), float(len(not_survived))/len(titanic)))

d) print(“Survived: (%.1f%%)” % (len(survived), float(len(survived))/len(titanic)*100))

print(“Not_Survived: (%.1f%%)” % (len(not_survived), float(len(not_survived))/len(titanic)*100))

ans:d

Asitdubey

Started my interest in Data Science and Machine Learning and want to learn more about it.