ENH: df.astype could accept a dict of {col: type} · Issue #7271 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@TomAugspurger

Description

@TomAugspurger

This would be consistent with other pandas methods.

The reason I'm running into it is having some NaNs scattered across some int and bool columns, which converts to float / objects. If I discard those NaNs, it would be nice to do

df = df.astype({'my_bool', 'bool', 'my_int': 'int'})

instead of

df['my_bool'] = df.my_bool.astype('bool') df['my_int'] = df.my_int.astype('int')