← 30 Days of Python
Day 10 / 30DataFrames

DataFrames — Core Operations

The DataFrame is the most important object in Python data analytics. If you master DataFrames, you can do 90% of what Excel does — and 100x faster on large data.

1
Easy

How do you create a DataFrame from a dictionary?

Python Answer
import pandas as pd

df = pd.DataFrame({
    "name": ["Rahul", "Priya", "Aman"],
    "age": [28, 25, 32],
    "salary": [60000, 75000, 90000]
})

df.shape    # (3, 3)
df.columns  # Index(["name", "age", "salary"])
df.dtypes   # types of each column
💡

Each dict key becomes a column. shape gives (rows, columns). Always check shape and dtypes immediately after loading data — it tells you if the import worked correctly.

2
Easy

How do you select columns and rows from a DataFrame?

Python Answer
df["name"]           # single column → Series
df[["name","salary"]] # multiple columns → DataFrame

df.iloc[0]           # first row by position
df.iloc[0:3]         # first 3 rows
df.loc[0, "name"]    # row 0, column "name"
df.loc[df["age"] > 27, ["name","salary"]]  # filter + select
💡

.iloc for position-based, .loc for label-based. The most important pattern: df.loc[condition, columns] — filter rows and select columns in one step.

3
Medium

How do you add, rename, and drop columns?

Python Answer
# Add column:
df["bonus"] = df["salary"] * 0.10
df["grade"] = df["age"].apply(lambda x: "senior" if x > 30 else "junior")

# Rename:
df.rename(columns={"name": "full_name"}, inplace=True)

# Drop:
df.drop(columns=["bonus"], inplace=True)
df.drop(columns=["bonus"])  # returns new df, original unchanged
💡

inplace=True modifies the DataFrame in memory. Without it, the operation returns a new DataFrame. Best practice: avoid inplace and reassign — it is clearer and avoids bugs.

4
Medium

How do you filter rows based on conditions?

Python Answer
df[df["salary"] > 70000]                     # single condition
df[(df["salary"] > 70000) & (df["age"] < 30)]  # AND
df[(df["salary"] > 90000) | (df["age"] < 26)]  # OR
df[df["name"].isin(["Rahul", "Aman"])]         # in list
df[df["name"].str.contains("ra", case=False)]  # text filter
💡

Never use Python and/or in Pandas conditions — use & and |. Each condition in parentheses. This is one of the most common beginner mistakes that causes TypeErrors.

5
Easy

How do you get summary statistics of a DataFrame?

Python Answer
df.describe()     # count, mean, std, min, max, quartiles
df.info()         # column types, non-null counts, memory
df.head(5)        # first 5 rows
df.tail(5)        # last 5 rows
df.sample(3)      # 3 random rows
df.shape          # (rows, cols)
df.isnull().sum() # null count per column
💡

This is your EDA starting sequence. Run all of these on any new dataset before touching a single column. info() reveals hidden issues — dtypes that should be numeric showing as object, for example.

EVIKA ACADEMY · PYTHON FOR DATA ANALYTICS

Want to master Python with live practice?

Join our Python for Data Analysis course — live classes in Noida and online across India.

Book Free Demo Class →
← PREVIOUSDay 9: Pandas Series — The FoundationNEXT →Day 11: Reading CSV, Excel & JSON Files
Best Data Analytics Course in Noida Delhi NCR | EVIKA ACADEMY