DAV - PYTHON LIBRARIES MODULE 1
INTERVIEW PREPARATION GUIDE
==================================================
PART 1: IMPORTANT CONCEPTS
==================================================
1. PANDAS
----------
Pandas is a Python library used for data manipulation and analysis.
Main Data Structures:
- Series (1D)
- DataFrame (2D)
Common Functions:
- read_csv()
- merge()
- sort_values()
- mean()
==================================================
2. PANDAS SERIES
==================================================
Series is a one-dimensional labeled array.
Example:
import pandas as pd
s = [Link]([10,20,30])
Mean:
[Link]()
Ignoring NaN:
[Link](skipna=True)
==================================================
3. PANDAS DATAFRAME MERGE
==================================================
Purpose:
Combine two DataFrames using a common column.
Syntax:
[Link](df1, df2,
on='column',
how='left')
Join Types:
left
right
inner
outer
Interview Point:
Left Join preserves all rows from the left DataFrame.
==================================================
4. NUMPY
==================================================
NumPy is used for numerical computation and array processing.
Creating Arrays:
import numpy as np
arr = [Link]([1,2,3])
==================================================
5. [Link]() VS [Link]()
==================================================
[Link]()
Returns True only if every condition is True.
Example:
[Link](arr > 0)
[Link]()
Returns True if at least one condition is True.
Example:
[Link](arr > 0)
==================================================
6. NUMPY ARRAY SLICING
==================================================
Example:
arr[-2:, -2:]
Meaning:
Select last two rows and last two columns.
==================================================
7. [Link]()
==================================================
Purpose:
Conditional replacement.
Syntax:
[Link](condition, value_if_true, value_if_false)
Example:
[Link](arr > 5, 1, 0)
==================================================
PART 2: INTERVIEW QUESTIONS & ANSWERS
==================================================
Q1. What is Pandas?
Answer:
Python library used for data analysis and manipulation.
--------------------------------------------------
Q2. Difference between Series and DataFrame?
Answer:
Series:
One-dimensional.
DataFrame:
Two-dimensional.
--------------------------------------------------
Q3. How do you read a CSV file in Pandas?
Answer:
pd.read_csv("[Link]")
--------------------------------------------------
Q4. What does skipna=True do?
Answer:
Ignores missing values while performing calculations.
--------------------------------------------------
Q5. What is a left join?
Answer:
Preserves all rows from the left DataFrame.
--------------------------------------------------
Q6. Difference between inner join and left join?
Answer:
Inner Join:
Only matching rows.
Left Join:
All rows from left table.
--------------------------------------------------
Q7. What is NumPy?
Answer:
Numerical computing library for Python.
--------------------------------------------------
Q8. What is [Link]()?
Answer:
Returns True only if all conditions are True.
--------------------------------------------------
Q9. What is [Link]()?
Answer:
Returns True if at least one condition is True.
--------------------------------------------------
Q10. What does arr[-2:, -2:] return?
Answer:
Last two rows and last two columns.
--------------------------------------------------
Q11. What is [Link]()?
Answer:
Conditional replacement function.
--------------------------------------------------
Q12. Why use feature filtering?
Answer:
To isolate important values based on conditions.
--------------------------------------------------
Q13. What is DataFrame sorting?
Answer:
Arranging rows using one or more columns.
--------------------------------------------------
Q14. How is total_cost calculated?
Answer:
total_cost = quantity * price
--------------------------------------------------
Q15. Why is Pandas important in Data Science?
Answer:
It simplifies data cleaning, transformation, analysis and reporting.
==================================================
QUICK REVISION NOTES
==================================================
read_csv() -> Read CSV files
[Link](skipna=True)
-> Mean ignoring NaN
[Link]()
-> Combine DataFrames
how='left'
-> Preserve left table
[Link]()
-> All conditions true
[Link]()
-> At least one condition true
arr[-2:, -2:]
-> Bottom-right 2x2 section
[Link]()
-> Conditional replacement
quantity * price
-> total_cost
==================================================
LAST MINUTE CHEAT SHEET
==================================================
pd.read_csv()
[Link](skipna=True)
[Link](df1, df2,
on='id',
how='left')
df.sort_values()
[Link]()
[Link]()
[Link]()
arr[-2:, -2:]