Ben Chuanlong Du's Blog

It is never too late to learn.

Cast Types of Columns in Pandas

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. You can use the method Series.astype to cast the type of a series.

  2. Series.astype(str) converts NaNs to the string literal nan. This is often NOT what people want. A better way is to use Series.astype(object) instead.

Comments