pandas.DataFrame.astype

DataFrame.astype(dtype, copy=True, errors='raise', **kwargs) [source]

Cast object to input numpy.dtype Return a copy when copy = True (be really careful with this!)

Parameters:

dtype : data type, or dict of column name -> data type

Use a numpy.dtype or Python type to cast entire pandas object to the same type. Alternatively, use {col: dtype, ...}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types.

errors : {‘raise’, ‘ignore’}, default ‘raise’.

Control raising of exceptions on invalid data for provided dtype.

  • raise : allow exceptions to be raised
  • ignore : suppress exceptions. On error return original object

New in version 0.20.0.

raise_on_error : DEPRECATED use errors instead

kwargs : keyword arguments to pass on to the constructor

Returns:

casted : type of caller

© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.20.3/generated/pandas.DataFrame.astype.html