DAI 101 Tutorial
DAI 101 Tutorial
NumPy
(a) (3,3)
(b) (3,2)
(c) (1,3)
(d) None
(a) numpy.search()
(b) numpy.find()
(c) numpy.contains()
(d) numpy.where()
Q.5 Which method finds the difference between two Numpy arrays?
(a) numpy.setdiff2d()
(b) numpy.setdiff1d()
(c) numpy.setdiff()
(d) numpy.diff()
import numpy as np
a1=np.array([[14,36],[17,47]])
a2=np.array([[10,15]])
a3=np.concatenate((a1,a2),axis=0)
print(a3)
a4=a3.reshape(2,3)
print()
print(a4)
Ans.
Q.9 what is/are the correct syntax to create an array of float type?
(a) Arr = np.array([1,2,3,4], dtype= ' float ')
(b) Arr = np.array([1,2,3,4], dtype= ' f ')
(c) Arr = np.array([1,2,3,4], dtype=float)
(d) None of the Above
(a) a1 = np.array([1,2,3])
a2=np.array([0,4,9])
a1.dot(a2)
(b) a1 = np.array([1,2,3,3])
a2=np.array([0,4,9])
np.add(a1,a2)
(c) a = np.array([[1,3,5],[4,6,8]])
np.sum (a)
print(np.zeros(5).dtype)
(a) int8
(b) int16
(c) uint8
(d) Float64
A. 5
B. 7
C. 3
D. 4
Pandas
Ans.
Q.18 Write a command to Find player who had highest BidPrice from each team.
Ans.
Ans.
Q.23 Which Pandas method can be used to handle large datasets by reading them in
chunks, and how can you specify the size of each chunk?
(a) read_csv() with the chunk_size parameter
(b) read_large_csv() with the buffer parameter
(c) read_csv() with the chunksize parameter
(d) read_csv_chunked() with the chunk_length parameter
Answer:
import pandas as pd
pd.Series([1, 2], index= ['a', 'b', 'c'])
(a) Syntax Error
(b) Index Error
(c) Value Error
(d) None of the above mentioned
Ans:
Q.26 Which of the following takes a dict of dicts or a dict of array-like sequences and
returns a DataFrame?
(a) DataFrame.from_items
(b) DataFrame.from_records
(c) DataFrame.from_dict
(d) All of the mentioned:
Q.28 What will be the result of executing the following code snippet?
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
result = df.groupby('A').agg({'B': lambda x: x.sum(), 'A': lambda x: x.mean()})
print(result)
(a) KeyError
(b) A DataFrame with separate aggregated results for 'A' and 'B'
(c) The same as the original DataFrame
(d) An empty DataFrame
Q.29 In a DataFrame df, how can you efficiently perform column-wise z-score
normalization, which standardizes each column so that it has a mean of 0 and a standard
deviation of 1?
(a) df.apply(lambda x: (x - x.mean()) / x.std(), axis=1)
(b) df.apply(lambda x: (x - x.mean()) / x.std(), axis=0)
(c) df.transform('zscore')
(d) None of the above
Q.30 How do you resolve mismatched indices during arithmetic operations between two
DataFrames?
(a) Use df1.align(df2) before operations to align both DataFrames.
(b) Use df1.reindex(df2.index).add(df2) for aligning indices followed by addition.
(c) Use pd.concat([df1, df2], axis=1) to force them to match.
(d) Rename the indices manually to ensure correspondence before operations.
Answer:
Q.32 What function does Pandas offer to calculate descriptive statistics that summarize the
central tendency, dispersion, and shape of a dataset’s distribution, excluding NaN values?
(a) describe()
(b) profiling()
(c) summary()
(d) overview()
Answer:
Q.33 In Pandas, which method is used to apply a function that takes single values and
returns single values to each element of a DataFrame?
(a) DataFrame.transform()
(b) DataFrame.apply()
(c) DataFrame.applymap()
(d) DataFrame.aggregate()
Answer:
Q.34 Which of the following operations is the most efficient way to create a copy of a
DataFrame in Pandas that includes only the first 100 rows of the original DataFrame?
Answer:
Q.35 How can you create a hierarchical index (MultiIndex) DataFrame and subsequently
access a subset of this DataFrame using both levels of indexing?
(a) Use pd.DataFrame.set_index(['col1', 'col2']) and access with df.loc[(value1, value2)]
(b) Use pd.MultiIndex.from_arrays() and access with df.xs((value1, value2))
(c) Use df.set_index() with a dictionary and access with df.ix[value1].ix[value2]
(d) Create a MultiIndex with pd.MultiIndex() and access directly with df['value1']['value2']
•
Q.36 What will be the minimum number of arguments required to pass in a pandas series?
(a) 2
(b) 3
(c) 4
(d) None of the above mentioned