I have a column, code_x. I converted it to .astype(str). Some example values are 45362.0, 75345.0, 346157.0, 572575.0. I would like them a
code_x
.astype(str)
45362.0, 75345.0, 346157.0, 572575.0
IIUC, you can use str.zfill which means you wouldn't have to special-case by length:
In [16]: ser Out[16]: 0 45362 1 75345 2 346157 3 572575 dtype: float64 In [17]: ser.astype(str).str.zfill(8) Out[17]: 0 045362.0 1 075345.0 2 346157.0 3 572575.0 dtype: object