Why would you pass dtype={'zip': 'string'} to pd.read_csv?
Correct answer
C. To stop pandas inferring ZIP codes as integers and stripping leading zeros
14 views
C. To stop pandas inferring ZIP codes as integers and stripping leading zeros
14 views
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.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.