Explanation:
๐น 1. Importing pandas (implicit step)
Before this code runs, you usually need:
import pandas as pd
✅ Explanation:
pandas is a powerful Python library used for data manipulation.
pd is just an alias (short name) for pandas to make typing easier.
๐น 2. Creating the DataFrame
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
✅ Explanation:
pd.DataFrame() creates a table-like structure (rows and columns).
The input is a dictionary:
'A': [1, 2] → Column A with values 1 and 2
'B': [3, 4] → Column B with values 3 and 4
๐ Resulting DataFrame:
index A B
0 1 3
1 2 4
๐ง Key Points:
Columns are A and B
Default index starts from 0
๐น 3. Accessing Data using .loc
print(df.loc[0, 'A'])
✅ Explanation:
.loc[] is used to access data by label (row index + column name)
๐ Breakdown:
0 → Row index
'A' → Column name
So:
๐ df.loc[0, 'A'] means
➡️ “Get value from row 0 and column A”
๐น 4. Output
1

0 Comments:
Post a Comment