ENH: df.astype
could accept a dict of {col: type} · Issue #7271 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
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')