ENH: accept dict of column:dtype as dtype argument in DataFrame.astype by StephenKappel · Pull Request #12086 · pandas-dev/pandas (original) (raw)
Continued in #13375
closes #7271
By passing a dict of {column name/column index: dtype}, multiple columns can be cast to different data types in a single command. Now users can do:
df = df.astype({'my_bool', 'bool', 'my_int': 'int'})
or:
df = df.astype({0, 'bool', 1: 'int'})
instead of:
df['my_bool'] = df.my_bool.astype('bool')
df['my_int'] = df.my_int.astype('int')