Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is Pandas in Python?
Pandas is an open-source data manipulation and analysis library for Python.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 2. How do you import the Pandas library?
import pandas as pd
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 3. How do you create a DataFrame in Pandas?
pd.DataFrame(data)
Example:
df = pd.DataFrame({'column1': [1, 2, 3], 'column2': ['a', 'b', 'c']})
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 4. How do you select specific columns from a DataFrame?
df[['column1', 'column2']]
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 5. How can you apply a function to each element in a DataFrame?
Use the apply function. df.apply(my_function)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 6. How can you rename columns in a Pandas DataFrame?
Use the rename function. df.rename(columns={'old_name': 'new_name'})
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 7. Explain the difference between Series and DataFrame in Pandas.
A Series is a one-dimensional labeled array, and a DataFrame is a two-dimensional table.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 8. How do you convert a Pandas DataFrame to a NumPy array?
Use the values attribute. df.values
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 9. How can you reset the index of a Pandas DataFrame?
Use the reset_index function. df.reset_index()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 10. How do you sort a Pandas DataFrame by a specific column?
Use the sort_values function. df.sort_values(by='column')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 11. What is the purpose of the to_csv function in Pandas?
to_csv is used to write a DataFrame to a CSV file.
Example:
df.to_csv('output.csv', index=False)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 12. How do you check for the existence of a specific value in a Pandas DataFrame?
Use the isin function. df['column'].isin([value])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 13. What is the purpose of the read_csv function in Pandas?
read_csv is used to read data from a CSV file into a DataFrame.
Example:
df = pd.read_csv('file.csv')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 14. Explain the use of the describe function in Pandas.
describe generates descriptive statistics of a DataFrame, excluding NaN values.
Example:
df.describe()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 15. How can you drop columns from a Pandas DataFrame?
Use the drop function. df.drop(['column1', 'column2'], axis=1)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 16. How do you handle duplicate values in a Pandas DataFrame?
Use the drop_duplicates() function. df.drop_duplicates()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 17. Explain the purpose of the to_datetime() function in Pandas.
to_datetime() is used to convert the argument to datetime.
Example:
df['date_column'] = pd.to_datetime(df['date_column'])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 18. How do you change the data type of a Pandas Series or DataFrame column?
Use the astype() function. df['column'] = df['column'].astype('new_dtype')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 19. Explain the purpose of the nlargest() function in Pandas.
nlargest() returns the first n largest elements from a DataFrame or Series.
Example:
df.nlargest(5, 'column')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 20. How can you create a Pandas DataFrame from a dictionary of Series or dictionaries?
Use the pd.DataFrame() constructor. df = pd.DataFrame({'column1': series1, 'column2': series2})
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 21. What is the purpose of the to_excel() function in Pandas?
to_excel() is used to write a DataFrame to an Excel file.
Example:
df.to_excel('output.xlsx', index=False)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 22. How do you calculate the correlation matrix for a Pandas DataFrame?
Use the corr() function. df.corr()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Intermediate / 1 to 5 years experienced level questions & answers
Ques 23. Explain the DataFrame in Pandas.
A DataFrame is a 2-dimensional labeled data structure with columns that can be of different types. It is similar to a spreadsheet or SQL table.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 24. What is the difference between loc and iloc in Pandas?
loc is label-based indexing, and iloc is integer-based indexing.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 25. Explain the use of the groupby function in Pandas.
groupby is used to split the data into groups based on some criteria and then apply a function to each group independently.
Example:
df.groupby('column1').mean()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 26. How do you handle missing data in a DataFrame?
df.dropna() or df.fillna(value)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 27. What is the purpose of the merge function in Pandas?
merge is used to combine two DataFrames based on a common column or index.
Example:
pd.merge(df1, df2, on='common_column')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 28. What is the purpose of the melt function in Pandas?
melt is used to transform wide-format data to long-format data.
Example:
pd.melt(df, id_vars=['id_column'], value_vars=['value_column'])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 29. Explain the concept of broadcasting in Pandas.
Broadcasting is the ability of NumPy and Pandas to perform operations on arrays or DataFrames of different shapes.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 30. What is the purpose of the concat function in Pandas?
concat is used to concatenate DataFrames along a particular axis.
Example:
pd.concat([df1, df2], axis=1)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 31. What is the purpose of the nunique function in Pandas?
nunique returns the number of unique elements in a Series or DataFrame.
Example:
df['column'].nunique()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 32. Explain the use of the cut function in Pandas.
cut is used to segment and sort data values into bins.
Example:
pd.cut(df['column'], bins=[0, 25, 50, 75, 100])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 33. Explain the concept of method chaining in Pandas.
Method chaining is a way of applying multiple operations on a DataFrame in a single line of code.
Example:
df.dropna().mean()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 34. What is the purpose of the iterrows() function in Pandas?
iterrows() is used to iterate over DataFrame rows as (index, Series) pairs.
Example:
for index, row in df.iterrows():
print(index, row['column'])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 35. Explain the use of the get_dummies() function in Pandas.
get_dummies() is used to convert categorical variable(s) into dummy/indicator variables.
Example:
pd.get_dummies(df['column'])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 36. What is the difference between Series.value_counts() and DataFrame['column'].value_counts()?
Series.value_counts() returns the counts of unique values in a Series, while DataFrame['column'].value_counts() returns counts for a specific column.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 37. What is the purpose of the pd.to_numeric() function?
pd.to_numeric() is used to convert argument to a numeric type.
Example:
df['column'] = pd.to_numeric(df['column'], errors='coerce')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 38. Explain the use of the pd.cut() function with the `bins` parameter.
pd.cut() is used to segment and sort data values into bins. The `bins` parameter defines the bin edges.
Example:
pd.cut(df['column'], bins=[0, 25, 50, 75, 100])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 39. How can you merge two DataFrames based on multiple columns?
Use the on parameter with a list of column names. pd.merge(df1, df2, on=['column1', 'column2'])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 40. How do you pivot a Pandas DataFrame using the pivot() function?
Use the pivot() function to reshape the DataFrame based on column values.
Example:
df.pivot(index='index_column', columns='column_to_pivot', values='value_column')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 41. What is the purpose of the crosstab() function in Pandas?
crosstab() computes a simple cross-tabulation of two (or more) factors.
Example:
pd.crosstab(df['factor1'], df['factor2'])
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 42. How do you apply a custom function to each element in a Pandas DataFrame?
Use the applymap() function. df.applymap(my_function)
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 43. Explain the concept of method chaining in Pandas.
Method chaining is a way of applying multiple operations on a DataFrame in a single line of code.
Example:
df.dropna().mean()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Experienced / Expert level questions & answers
Ques 44. Explain the pivot_table function in Pandas.
pivot_table is used to create a spreadsheet-style pivot table as a DataFrame.
Example:
pd.pivot_table(df, values='value', index='index_column', columns='column_to_pivot')
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 45. Explain the concept of MultiIndex in Pandas.
MultiIndex is used to represent hierarchical index levels in a DataFrame.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 46. Explain the use of the transform() function in Pandas.
transform() is used to perform group-specific computations and return a DataFrame with the same shape as the input.
Example:
df['normalized_column'] = df.groupby('group_column')['value_column'].transform(lambda x: (x - x.mean()) / x.std())
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 47. What is the purpose of the pipe() function in Pandas?
pipe() is used to apply a function to a DataFrame using method chaining.
Example:
df.pipe(my_function).dropna()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 48. Explain the purpose of the stack() and unstack() functions in Pandas.
stack() is used to pivot the columns of a DataFrame to the rows. unstack() does the reverse operation.
Example:
df.stack()
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Most helpful rated by users:
- What is Pandas in Python?
- How do you select specific columns from a DataFrame?
- How do you import the Pandas library?
- How can you apply a function to each element in a DataFrame?
- How can you rename columns in a Pandas DataFrame?
Related interview subjects
| Pandas interviewfragen und antworten - Total 30 questions |
| Deep Learning interviewfragen und antworten - Total 29 questions |
| Flask interviewfragen und antworten - Total 40 questions |
| PySpark interviewfragen und antworten - Total 30 questions |
| PyTorch interviewfragen und antworten - Total 25 questions |
| Data Science interviewfragen und antworten - Total 23 questions |
| SciPy interviewfragen und antworten - Total 30 questions |
| Generative AI interviewfragen und antworten - Total 30 questions |
| NumPy interviewfragen und antworten - Total 30 questions |
| Python interviewfragen und antworten - Total 106 questions |
| Python Pandas interviewfragen und antworten - Total 48 questions |
| Django interviewfragen und antworten - Total 50 questions |
| Python Matplotlib interviewfragen und antworten - Total 30 questions |