There are no items in your cart
Add More
Add More
Item Details | Price |
---|
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
original_data = pd.DataFrame(mydata[‘my_column’])
scaled_data = pd.DataFrame(scaler.fit_transform(original_data))
def find_missing_num(input):
sum_of_elements = sum(input)
n = len(input) + 1
real_sum = (n * ( n + 1 ) ) / 2
return int(real_sum - sum_of_elements)
mylist = [1,5,6,3,4]
find_missing_num(mylist)
For serializing and de-serializing any given object in Python, we make use of the pickle module. In order to save given object on drive, we make use of pickle. It converts an object structure into character stream
>>import numpy as np
>>arr=np.array([10, 30, 20, 40, 50])
>>print(arr.argsort( ) [ -N: ][: : -1])
.pyc files contain the compiled bytecode of Python source files. The Python interpreter loads .pyc files before .py files, so if they're present, it can save some time by not having to re-compile the Python source code.
A local variable is any variable declared within a function. This variable exists only in local space, not in global space. Global variables are variables declared outside of a function or in a global space. Any function in the program can access these variables.
Lambda functions are anonymous functions in Python. It's helpful when you need to define a function that's very short and consists of only one expression. So, instead of formally defining the small function with a specific name, body, and return statement, you can write everything in one short line of code using a lambda function.
Here's an example of how lambda functions are defined and used:
(lambda x, y,: (x+y))
(3,2)
5
A negative index is used in Python to index a list, string, or any other container class in reverse order (from the end). Thus, [-1] refers to the last element, [-2] refers to the second-to-last element, and so on.
Vectorization is basically the process of implementing operations on the dataframe without using loops. We instead use functions that are highly optimized. For example, if I want to calculate the sum of all the rows of a column in a dataframe, instead of looping over each row, I can use the aggregation functionality that pandas provides and calculate the sum.
PYTHONPATH tells the python Interpreter where to locate module files imported into a program. The role is similar to PATH. PYTHONPATH includes both the source library directory and the source code directories.
Both / and // are division operators. However, / does float division, dividing the first operand by the second. / returns the value in decimal form. // does floor division, dividing the first operand by the second, but returns the value in natural number form.
Q12 - You are given test scores, write python code to return bucketed scores of <50, <75, <90, <100.
bins = [0, 50, 75, 90, 100]
labels=['<50','<75','<90' , '<100']
df['test score'] = pd.cut(df['test score'], bins,labels=labels)
return df
Q13 - How can you obtain the principal components and the eigenvalues from Scikit-Learn PCA?
from sklearn.decomposition import PCA
import numpy as np
data = np.array([[2.5, 2.4], [0.5, 0.7], [1.1, 0.9]])
pca = PCA()
pca.fit(data)
eigenvectors
print(pca.components_)
eigenvalues
print(pca.explained_variance_)
Q14 - What is a Python dictionary and how do you use it?
A Python dictionary is an unordered collection of items, each defined by a key-value pair. You can create a dictionary using curly braces {}
or the dict()
function. For example:
Q15 - How do you handle missing values in a pandas DataFrame?
Q16 - Explain the difference between loc
and iloc
in pandas.
loc
is label-based, meaning you have to specify the names of the rows and columns you want to filter. iloc
is integer index-based, so you must specify the rows and columns by their integer index.
Q17 - What are Python list comprehensions and provide an example?
List comprehensions provide a concise way to create lists. It consists of brackets containing an expression followed by a
for
clause, then zero or more for
or if
clauses.
Q18 - How do you merge two DataFrames in pandas?
DataFrames can be merged using the
merge()
function in pandas. You can specify the keys on which to join the DataFrames.
Q19 - Explain the difference between map()
, apply()
, and applymap()
in pandas.
map()
: Used to substitute each value in a Series with another value.apply()
: Used to apply a function along an axis of the DataFrame.applymap()
: Used to apply a function element-wise across a DataFrame.Q20 - How do you remove duplicates from a pandas DataFrame?
Q20 - Explain the concept of broadcasting in NumPy.
Q21 - What is a decorator in Python, and how do you use it?
Q22 - Explain the concept of metaclasses in Python.
Metaclasses are classes of classes, meaning they define how classes behave. A class is an instance of a metaclass. By default, Python uses type
as the metaclass, but you can define custom metaclasses to control class creation.
Q23 - How does the @staticmethod
decorator differ from @classmethod
?
@staticmethod
defines a method that doesn't operate on an instance or class level, effectively being a function within the class namespace.
@classmethod
, on the other hand, takes
cls
as the first parameter and can modify the class state
Q24 - What is a generator in Python, and how is it different from a normal function?
Generators are functions that return an iterable set of items, one at a time, in a special way using yield
instead of return
. They save memory and are used for large datasets or streams.
Q25 - What are Python coroutines, and how do they differ from generators?
Coroutines are similar to generators but are used for cooperative multitasking. They can be paused and resumed, allowing for asynchronous I/O operations. Coroutines use async
and await
keywords.
Q26 - What are context managers and the with
statement used for in Python?
with
statement simplifies exception handling by encapsulating common preparation and cleanup tasks.
Q27 - Explain Python's memory management and garbage collection.
Q28 - How do you create and use a custom exception in Python?
Exception
class. They can add additional attributes and methods to the base exception class.
Q29 - What is the purpose of the __new__
method in Python?
__new__
is a static method responsible for creating a new instance of a class. It is called before
__init__
, and is typically used in singleton patterns or when subclassing immutable types.
Q30 - Explain the Global Interpreter Lock (GIL) in Python. How does it affect multi-threading?