Data Science Interview Qs Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q
  1. Name a function which is most useful to convert a multidimensional array into a one-dimensional array. For this function will changing the output array affect the original array?
A

The flatten( ) can be used to convert a multidimensional array into a 1D array. If we modify the output array returned by flatten( ), it will not affect the original array because this function returns a copy of the original array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. If there are two variables defined as ‘a = 3’ and ‘b = 4’, will ID() function return the same values for a and b?
A

The id() function in python returns the identity of an object, which is actually the memory address. Since, this identity is unique and constant for every object, it will not return same values for a and b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What is Beautiful soup library used for?
A

Beautiful Soup is a Python library for getting data out of HTML, XML, and other markup languages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. In python, if we create two variables ‘mean = 7’ and ‘Mean = 7’ , will both of them be considered as equivalent?
A

Python is a case-sensitive language. It has the ability to distinguish uppercase or lowercase letters and hence these variables ‘mean = 7’ and ‘Mean = 7’ will not be considered as equivalent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What is the use of ‘inplace’ in pandas functions?
A

Inplace is a parameter available for a number of pandas functions. It impacts how the function executes. Using ‘inplace = True’, the original dataframe can be modified and it will return nothing. The default behaviour is ‘inplace = False’ which returns a copy of the dataframe, without affecting the original dataframe.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. How can you change the index of a dataframe in python?
A

DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False) keys: label or array-like or list of labels/arrays This parameter can be either a single column key, a single array of the same length as the calling DataFrame, or a list containing an arbitrary combination of column keys and arrays. Here, “array” encompasses Series, Index, np.ndarray, and instances of Iterator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How would check a number is prime or not using Python?
A

taking input from user number = int(input(“Enter any number: “)) # prime number is always greater than 1 if number > 1: for i in range(2, number): if (number % i) == 0: print(number, “is not a prime number”) break else: print(number, “is a prime number”) # if the entered number is less than or equal to 1 # then it is not a prime number else: print(number, “is not a prime number”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What is the difference between univariate and bivariate analysis? What all different functions can be used in python?
A

Univariate analysis summarizes only one variable at a time while Bivariate analysis compares two variables. Below are a few functions which can be used in the univariate and bivariate analysis: 1. To find the population proportions with different types of blood disorders. df.Thal.value_counts() 2. To make a plot of the distribution : sns.distplot(df.Variable.dropna()) 3. Find the minimum, maximum, average, and standard deviation of data. There is a function called describe() which returns the minimum, maximum, mean etc. of the numerical variables of the data frame. 4. Find the mean of the Variable df.Variable.dropna().mean() 5. Boxplot to observe outliers sns.boxplot(x = ‘ ‘, y = ‘ ‘, hue = ‘ ‘, data=df) 6. Correlation plot: data.corr()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. What is the difference between ‘for’ loop and ‘while’ loop?
A
  • ‘for’ loop is used to obtain a certain result. In a for loop, the number of iterations to be performed is already known. - In ‘while’ loop, the number of iterations is not known. Here, the statement runs until a specific condition is met and the assertion is proven untrue.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Differentiate between Call by value and Call by reference.
A

In the Call by Value method, there is no modification in the original value. In the Call by Reference method, there is a modification in the original value. In the case of Call by Value, when we pass the value of the parameter during the calling of the function, it copies them to the function’s actual local argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. How will you import multiple excel sheets in a data frame?
A

The excel sheets can be read using ‘pd.read_excel()’ function into a dataframe and then using ‘pd.concat()’, concatenate all the excel sheets- Syntax: df = pd.concat(pd.read_excel(‘sheet_name’, sheet_name=None), ignore_index=True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. What is the difference between ‘Append’ and ‘Extend’ function?
A

The append() method adds an item to the end of the list. The syntax of the append() method is: list.append(item) On the other hand, the extend method extends the list by adding each element from iterable. The syntax of the extend() method is: list.extend(item)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. What are the data types available in Python?
A

Python has the following standard data types: - Boolean - Set - Mapping Type: dictionary - Sequence Type: list, tuple, string - Numeric Type: complex, float, int.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. Can you write a function using python to impute outliers?
A

import numpy as np def remove Outliers(x, outlierConstant): a = np.array(x) upper_quartile = np.percentile(a, 75) lower_quartile = np.percentile(a, 25) IQR = (upper_quartile - lower_quartile) * outlierConstant quartileSet = (lower_quartile - IQR, upper_quartile + IQR) resultList = for y in a.tolist(): if y > = quartileSet[0] and y < = quartileSet[1]: resultList.append(y) return resultList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. Can any type of string be converted into an int, in Python?
A

Python offers the int() method that takes a String object as an argument and returns an integer. This can be done only when the value is either of numeric object or floating-point. But keep these special cases in mind - A floating-point (an integer with a fractional part) as an argument will return the float rounded down to the nearest whole integer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. How would check a number is armstrong number using Python?
A

Python program to check if the number is an Armstrong number or not # take input from the user num = int(input(“Enter a number: “)) # initialize sum sum = 0 # find the sum of the cube of each digit temp = num while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 # display the result if num == sum: print(num,”is an Armstrong number”) else: print(num,”is not an Armstrong number”)

17
Q
  1. What is the difference between list, array and tuple in Python?
A

The list is an ordered collection of data types. The list is mutable. Lists are dynamic and can contain objects of different data types. List elements can be accessed by index number An array is an ordered collection of similar data types. An array is mutable. An array can be accessed by using its index number. Tuples are immutable and can store any type of data type. It is defined using (). It cannot be changed or replaced as it is an immutable data type

18
Q
  1. What is the difference between iloc and loc activity?
A

loc gets rows (or columns) with particular labels from the index. iloc gets rows (or columns) at particular positions in the index and it only takes integers.

19
Q
  1. How does the reverse function work in Python?
A

The built-in reverse( ) function reverses the contents of a list object inplace. That means, it does not return a new instance of the original list, rather it makes a direct change to the original list object. Syntax: list.reverse()

20
Q
  1. What is the apply function in Python? How does it work?
A

Pandas.apply allow the users to pass a function and apply it on every single value of the Pandas series. Syntax: s.apply(func, convert_dtype=True, args=())