What are the different ways to create a DataFrame in Pandas?

Quick Overview

Asks for the ways to build a pandas DataFrame from Python objects, NumPy arrays, Series, files and databases. Tests how each constructor handles columns, index alignment and missing values, and how to avoid slow row-by-row construction.

What are the different ways to create a DataFrame in Pandas?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What are the different ways to create a `DataFrame` in Pandas? ```hint Group by source Organize the answer by where the data comes from (Python containers, NumPy, existing Series, files or databases), and think about what happens when rows or Series do not line up. ``` ### What a Strong Answer Covers - Construction from Python containers: a dict of lists, a list of dicts, and a list of lists with column names. - Construction from a NumPy array and from Series, including how the index aligns. - The readers for files and databases. - How missing keys, unequal lengths and scalar values are handled. - Why growing a DataFrame row by row is slow and what to do instead. ### Follow-up Questions - You collect 100,000 API records in a loop. How would you turn them into a DataFrame efficiently? - What happens when you build a DataFrame from two Series with different indexes? - How do you build a DataFrame from a dict when each key should become a row instead of a column? - How would you load a CSV file that does not fit in memory?

Overview: Asks for the ways to build a pandas DataFrame from Python objects, NumPy arrays, Series, files and databases. Tests how each constructor handles columns, index alignment and missing values, and how to avoid slow row-by-row construction.

Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What are the different ways to create a DataFrame in Pandas?

What a Strong Answer Covers Guidance

  • Construction from Python containers: a dict of lists, a list of dicts, and a list of lists with column names.
  • Construction from a NumPy array and from Series, including how the index aligns.
  • The readers for files and databases.
  • How missing keys, unequal lengths and scalar values are handled.
  • Why growing a DataFrame row by row is slow and what to do instead.

Follow-up Questions Guidance

  • You collect 100,000 API records in a loop. How would you turn them into a DataFrame efficiently?
  • What happens when you build a DataFrame from two Series with different indexes?
  • How do you build a DataFrame from a dict when each key should become a row instead of a column?
  • How would you load a CSV file that does not fit in memory?