Skip to main contentSkip to solution

A DataFrame can be created from:-

(A) Dictionary of lists

(B) List of dictionaries

(C) Numpy array

(D) Series

Solution

✅ Correct Option: 3

All four can be passed to pd.DataFrame():

(A) Dictionary of lists: keys become column names and each list becomes a column.

(B) List of dictionaries: each dictionary becomes a row, and keys become column names.

(C) Numpy array: a 2D array becomes rows and columns.

(D) Series: pd.DataFrame(s) gives a one-column DataFrame, and a dictionary of Series gives several columns.


Option 2: a common mistake is to think a 1D Series cannot form a DataFrame, but it can, as a single column.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question