Skip to content

ENH: df.astype could accept a dict of {col: type} #7271

Closed
@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')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions