Tricky Python Quiz For Data Science And Machine Learning Interviews! #39
A quick knowledge check!
Hello Everyone,
Welcome to the 39th edition of my newsletter ML & AI Cupcakes!
In today’s newsletter, I have compiled a set of some basic, but tricky MCQs to help you access your python skills for data science and machine learning interviews.
Please note that standard notations have been used for importing libraries wherever needed.
import numpy as np
import pandas as pd
Good luck!
Which function is used to calculate mean in numpy?
mean()
average()
sum()
mode()
Which of the following is a valid pandas function?
pd.read_pickle()
pd.read_html()
pd.read_csv()
All of the above
Which data structure is immutable?
Set
Tuple
List
Dictionary
Which data structure doesn’t allow duplicate elements?
Set
Tuple
List
Dictionary
What will be the output of len ([2, 3, [2,2,3], np.nan, [1,0]])?
4
5
7
8
What is the outcome of my_list.append([2,3,4])?
adds 2, 3 and 4 as individual items in my_list
adds [2,3,4] as a sublist in my_list
appends only 2 to my_list
throws an error
What is the outcome of my_list.extend([2,3,4])?
adds 2, 3 and 4 as individual items in my_list
adds [2,3,4] as a sublist in my_list
replaces the existing list
throws an error
Which of the following is true about np.nanmean()?
throws an error
gives NaN as output
calculates mean by ignoring NaN values
replace NaNs with mean value
Which of the following is used to check NaN values in a numpy array?
pd.isnull()
np.isnull()
np.isna()
np.isnan()
What will be the output of np.eye(4)?
4x4 matrix of zeros
4x4 matrix of ones
4x4 identity matrix
Diagonal matrix with 4s
What does arr1[2:4] will return for arr1 = np.array([34, 12, 45, 33, 78 , 90])?
[12, 45, 33]
[12, 45]
[45, 33]
[45, 33, 78]
Which axis refers to rows in a pandas dataframe?
-1
0
1
2
What is the output of df.shape?
number of rows
numer of columns
number of rows*number of columns
(number of rows, number of columns)
What gives the frequency of unique values in a column?
df[‘col’].unique()
df[‘col’].nunique()
df[‘col’].value_counts()
df[‘col’].isnull()
Which method is used to remove duplicate rows in a pandas dataframe?
drop_duplicates()
remove_duplicates()
dropna()
clean()
what does df.iloc[1] returns in a dataframe?
first row
second row
last row
column names
Which of the following returns count of missing values in each column of a pandas dataframe?
df.isnull()
df.isnull().sum()
df.isnan()
df.isnan().sum()
Which of the following will give unique values from a column in a pandas dataframe?
df[‘col’].values()
df['col'].unique()
df['col'].unique_values()
df['col'].unique_counts()
Which of the following will return basic summary stats for numerical columns in a pandas dataframe?
df.head()
df.info()
df.tail()
df.describe()
What will be the output of df[np.isnan(df[‘col'])]?
returns the dataframe excluding rows with null values
returns the rows with null values in column ‘col’
returns the rows with zero values
returns first 5 rows of the dataframe
What is not returned by df.info()?
memory usage
data types
mean values
column names
What will be the outcome of df[df['TotalCharges']>8600]?(Please note that df dataframe contains 5 columns)
returns a boolean series
returns the index of matching rows
returns only the 'TotalCharges' column
returns rows where 'TotalCharges' are greater than 8600
You want rows where ‘tenure’ is less than 5 and ‘MonthlyCharges’ are less than 35. Which of the following syntax will give you the results?
df.loc[(df['tenure']<5)& (df['MonthlyCharges']<35)]
df.loc[(df['tenure']<5)& (df['MonthlyCharges']>35)]
df.loc[(df['tenure']>5 $ (df['MonthlyCharges']<35)]
df.loc[(df['tenure']>5) || (df['MonthlyCharges']<35)]
Answers
a 2. d 3. b 4. a 5. b 6. b 7. a 8. c 9. d 10. c 11. c 12. b 13. d 14. c 15. a
16. b 17. b 18. b 19. d 20. b 21. c 22. d 23.a
Writing each newsletter takes a lot of research, time and effort. Just want to make sure it reaches maximum people to help them grow in their AI/ML journey.
It would be great if you could share this newsletter with your network.
Also, please let me know your feedbacks and suggestions in the comments section. That will help me keep going. Even a “like” on my posts will tell me that my posts are helpful to you.
See you soon!
-Kavita
Great questions to refresh pyhthon knowledge.Thank you
good stuff