How can you read and write data from and to a CSV file in Pandas?

Quick Overview

Asks how to load a CSV file into a pandas DataFrame and save a DataFrame back to CSV. Tests practical knowledge of the common reading options, how the row index behaves when a file is written and read again, and how to handle files too large for memory.

How can you read and write data from and to a CSV file in Pandas?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

How can you read and write data from and to a CSV file in Pandas? Describe the functions you would call and the options that matter most for a typical file. ```hint Round trip Think about what happens to the row index when you write a DataFrame to CSV and later read that file back. ``` ### What a Strong Answer Covers - The function that loads a CSV into a DataFrame and the method that writes one out, with a short example. - The read options that come up most: delimiter, header row, index column, column selection, types, dates and missing-value markers. - How the row index is handled on write and on the next read, so a round trip neither adds nor loses a column. - What to do when a file is too large to load comfortably in memory. ### Follow-up Questions - How would you compute a per-group sum over a 20 GB CSV without loading the whole file? - Why can a column of ZIP codes or account IDs come back wrong after reading, and how do you prevent it? - When would you store intermediate results as Parquet instead of CSV? - How do you read a file that uses a non-UTF-8 encoding or a comma as the decimal separator?

Overview: Asks how to load a CSV file into a pandas DataFrame and save a DataFrame back to CSV. Tests practical knowledge of the common reading options, how the row index behaves when a file is written and read again, and how to handle files too large for memory.

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

How can you read and write data from and to a CSV file in Pandas? Describe the functions you would call and the options that matter most for a typical file.

What a Strong Answer Covers Guidance

  • The function that loads a CSV into a DataFrame and the method that writes one out, with a short example.
  • The read options that come up most: delimiter, header row, index column, column selection, types, dates and missing-value markers.
  • How the row index is handled on write and on the next read, so a round trip neither adds nor loses a column.
  • What to do when a file is too large to load comfortably in memory.

Follow-up Questions Guidance

  • How would you compute a per-group sum over a 20 GB CSV without loading the whole file?
  • Why can a column of ZIP codes or account IDs come back wrong after reading, and how do you prevent it?
  • When would you store intermediate results as Parquet instead of CSV?
  • How do you read a file that uses a non-UTF-8 encoding or a comma as the decimal separator?