Cast a pandas object to a specified dtype dtype.

param 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.

param copy
bool, default True

Return a copy when copy=True (be very careful setting copy=False as changes to values then may propagate to other pandas objects).

param 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.

param kwargs

keyword arguments to pass on to the constructor


casted : same type as caller


  • Currently copy=False is not supported


Cast a pandas object to a specified dtype dtype.
import numpy as np
import pandas as pd
from numba import njit

def series_astype():
    series = pd.Series([3, -10, np.nan, 0, 92])

    return series.astype(str)

$ python ./series/
0      3.000000
1    -10.000000
2           nan
3      0.000000
4     92.000000
dtype: object

See also


Convert argument to datetime.


Convert argument to timedelta.


Convert argument to a numeric type.


Copy of the array, cast to a specified type.