1. Home
  2. Data Science
  3. Pandas
  4. Why would you pass dtype={'zip': 'string'} to pd.read_csv?

Added 30 Nov -0001

Why would you pass dtype={'zip': 'string'} to pd.read_csv?

  1. To skip that column entirely while reading, so it never appears in the frame
  2. To speed up parsing by disabling the C engine and using the Python parser
  3. To stop pandas inferring ZIP codes as integers and stripping leading zeros Correct answer
  4. To force every column in the file to be parsed as text rather than numbers

Correct answer

C. To stop pandas inferring ZIP codes as integers and stripping leading zeros

14 views

MCQSEXAM

Explanation

Dtype control on read: inference turns 01234 into the integer 1234, destroying the leading zero, so declaring the column as string preserves the original digits. dtype applies per column, whereas dtype=str would affect all columns, and converters can transform values on the fly. Postal codes, phone numbers and account identifiers generally need this treatment.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs