pandas.DataFrame.astype

pandas 3.1.1 · DataFrame · method

Convert to another dtype. A DataFrame accepts a mapping to choose conversions column by column.

Call syntax

DataFrame.astype(dtype, copy=…, errors='raise')

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
dtype Required
Positional or keyword
str, data type, Series or Mapping of column name -> data type

Choose the data type for the input conversion or result.

copy Optional
Positional or keyword
bool

Control whether data is copied where the API supports that choice.

errors Optional
Positional or keyword
Default 'raise'
{'raise', 'ignore'}

Choose how to handle invalid input or failed operations. The available options depend on the API.

Returns

same type as caller