15 commonly asked Python interview questions - Google Docs
15 commonly asked Python interview questions - Google Docs
● sedf.isnull().sum()to check missing values.
U
● Fill missing values usingdf.fillna(value, method='ffill'/'bfill').
● Remove missing values withdf.dropna().
Example:
f.fillna(df.mean()) # Fill NaNs with column mean
d
df.dropna() # Remove rows with NaNs
● : Label-based indexing.
loc[]
●
iloc[] : Integer-based positional indexing.
Example:
f.loc[2, 'Age'] # Access by row label
d
df.iloc[2, 1] # Access by row and column index
● umeric:int,float,complex
N
● Sequence:list,tuple,range,str
● Set:set,frozenset
● Mapping:dict
● Boolean:bool
● Binary:bytes,bytearray,memoryview
● : Used for Series (element-wise transformations).
map()
●
apply() : Used for both Series and DataFrames (column-wiseor row-wise
transformations).
Example:
f['column'].map(lambda x: x * 2) # Applies function to each value
d
df.apply(lambda x: x.sum(), axis=0) # Sum of each column
● merge() : Used for complex joins (like SQL joins) oncolumns.
● : Used for joining on index.
join()
Example:
df1.join(df2, on='ID', how='left')
12. How can you concatenate two DataFrames vertically and horizontally?
Usepd.concat().
Example:
Vertical (stack rows)
#
df_vertical = pd.concat([df1, df2], axis=0)
● seIQR method: Remove values outside1.5 * IQR.
U
● UseZ-score: Remove values with|Z-score| > 3.
● UseWinsorization: Cap outliers instead of removingthem.
Example:
rom scipy import stats
f
df = df[(np.abs(stats.zscore(df['column'])) < 3)]