Friday, 22 August 2025

Python Interview Questions with Answers Part-5: ☑️

 41. How do you handle categorical data?  

    Use encoding techniques like one-hot encoding (pd.get_dummies()), label encoding, or ordinal encoding to convert categories into numeric values.

42. Explain the difference between deep copy and shallow copy.
Shallow copy copies an object but references nested objects.
Deep copy copies everything recursively, creating independent objects.

43. What is the use of the enumerate() function?  
    Adds a counter to an iterable, yielding pairs (index, value) great for loops when you need the item index as well.

44. How do you detect and handle multicollinearity?  
    Use correlation matrix or Variance Inflation Factor (VIF). Handle by removing or combining correlated features.

45. How can you improve Python script performance?  
    Use efficient data structures, built-in functions, vectorized operations with NumPy/Pandas, and profile code to identify bottlenecks.

46. What are Python’s built-in data structures?  
    List, Tuple, Set, Dictionary, String.

47. How do you automate repetitive data tasks with Python?  
    Write scripts or use task schedulers (like cron/Windows Task Scheduler) with libraries such as pandas, openpyxl, and automation tools.

48. Explain the use of Assertions in Python.  
    Used for debugging by asserting conditions that must be true, raising errors if violated: 
    assert x > 0, "x must be positive"

49. How do you write unit tests in Python?  
    Use unittest or pytest frameworks to write test functions/classes that verify code behavior automatically.

50. How do you handle large datasets in Python?  
    Use chunking with Pandas read_csv(chunk_size=…), Dask for parallel computing, or databases to process data in parts rather than all at once.

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...