DataFrame Creation and Columns

easypandas_basics

Implement two functions.

make_dataframe(columns) columns is a dict {column_name: [v1, v2, ...]}. Create and return a pd.DataFrame from it. Column order must match the dict's insertion order.

add_product_column(df, col_a, col_b, result) Return a copy of df with a new column result = df[col_a] * df[col_b]. The original DataFrame must not be modified.

df = make_dataframe({"price": [10, 20], "qty": [3, 5]})
df2 = add_product_column(df, "price", "qty", "total")
# df2["total"] == [30, 100]; df unchanged

Your solution

Edit make_dataframe and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

pd.DataFrame(dict) creates a DataFrame where each key becomes a column and the list becomes its values.

Hint 2

To add a column without mutating the input, call df.copy() first, then assign: df[result] = df[a] * df[b].