Friday, 22 August 2025

Python Interview Questions with Answers Part-3:

 21. How do you perform basic statistical operations in Python?  

    Use libraries like NumPy (np.mean(), np.median(), np.std()) and Pandas (df.describe()) for statistics like mean, median, variance, etc.

22. What libraries do you use for data visualization?  
    Common ones are Matplotlib, Seaborn, Plotly, and sometimes Bokeh for interactive plots.

23. How do you create plots using Matplotlib or Seaborn?  
    In Matplotlib:

Python

import matplotlib.pyplot as plt
plt.plot(x, y)
plt.show()
In Seaborn:

Python

import seaborn as sns
sns.barplot(x='col1', y='col2', data=df)

24. What is the difference between .apply() and .map() in Pandas?
⦁ .apply() can work on entire Series or DataFrames and accepts functions.
⦁ .map() maps values in a Series based on a dict, Series, or function.

25. How do you export Pandas DataFrames to CSV or Excel files?  
    Use df.to_csv('file.csv') or df.to_excel('file.xlsx').

26. What is the difference between Python’s range() and xrange()?  
    In Python 2, range() returns a list, xrange() returns an iterator for better memory usage. In Python 3, range() behaves like xrange().

27. How can you profile and optimize Python code?  
    Use modules like cProfile, timeit, or line profilers to find bottlenecks, then optimize with better algorithms or vectorization.

28. What are Python decorators and give a simple example?  
    Functions that modify other functions without changing their code. 
    Example:

Python

def decorator(func):
    def wrapper():
        print("Before")
        func()
        print("After")
    return wrapper

@decorator
def say_hello():
    print("Hello")

29. How do you handle dates and times in Python?  
    Use datetime module and libraries like pandas.to_datetime() or dateutil to parse, manipulate, and format dates.

30. Explain list slicing in Python.  
    Get sublists using syntax list[start:stop:step]. Example: lst[1:5:2] picks items from index 1 to 4 skipping every other.

No comments:

Post a Comment

Euromonitor Recruitment Drive 2025 – Hiring Associate Data Analyst | Apply Now

  Associate Data Analyst Job Openings in Bangalore 2025 Job Overview Position: Associate Data Analyst Team: Catalyst (Foundational D...