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.
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
| 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 |
| Python Matplotlib interviewfragen und antworten - Total 30 questions |
| Django interviewfragen und antworten - Total 50 questions |
| 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 |