Basic Questions Flashcards
(34 cards)
Name a function which is most useful to convert a multidimensional array into a one-dimensional array.
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.
If there are two variables defined as ‘a = 3’ and ‘b = 4’, will id() function return the same values for a and b?
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.
In python, if we create two variables ‘mean = 7’ and ‘Mean = 7’, will both of them be considered as equivalent?
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.
What is the use of ‘inplace’ in pandas functions?
‘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 can you change the index of a dataframe in python?
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.
How would check a number is prime or not using Python?
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”)
What is the difference between univariate and bivariate analysis? What all different functions can be used in python?
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()
What is the difference between ‘for’ loop and ‘while’ loop?
‘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 will you import multiple excel sheets in a data frame?
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)
What is the difference between ‘Append’ and ‘Extend’ function?
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)
What are the data types available in Python?
Python has the following standard data types: - Boolean - Set - Mapping Type: dictionary - Sequence Type: list, tuple, string - Numeric Type: complex, float, int.
Can you write a function using python to impute outliers?
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
Can any type of string be converted into an int, in Python?
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 would check a number is armstrong number using Python?
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”)
What is the difference between list, array and tuple in Python?
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.
What is the difference between iloc and loc activity?
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.
How does the reverse function work in Python?
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()
What is the apply function in Python? How does it work?
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=())
How do you get the frequency of a categorical column of a dataframe using python?
Using df.value_counts(), where df is the dataframe. The value_counts( ) function returns the counts of the distinct elements in a dataframe column, sorted in descending order by default.
Will range(5) include ‘5’ in its output?
The range() function in python always excludes the last integer from the result. Here it will generate a numeric series from ‘0’ to (5-1)=4, and it will not include ‘5’.
How can you drop a column in python?
Pandas ‘drop()’ method is used to remove specific rows and columns. To drop a column, the parameter ‘axis’ should be set as ‘axis = 1’. This parameter determines whether to drop labels from the columns or rows (index). Default behaviour is, axis = 0. Syntax: df.drop(‘column_name’, axis=1)
How NaN values behave while comparing with itself?
NaN values can not be compared with itself. That’s why, checking if a variable is equal to itself is the most popular way to look for NaN values. If it isn’t, it’s most likely a NaN value.
How can we convert a python series object into a dataframe?
The to_frame() is a function that helps us to convert a series object into a dataframe. Syntax: Series.to_frame(name=None) name: this name will substitute the existing series name while creating the dataframe.
What is supervised learning?
Supervised learning is a type of machine learning method in which algorithms are trained using well labeled training data, with independent variables tagged against a defined target variable. This technique allows for predictions and comparisons against the ground truth.
Example: Determining if a client might default on a loan or not.