def astype(self, dtype, copy=True, errors='raise', **kwargs):
    "\n        Cast a pandas object to a specified dtype ``dtype``.\n\n        Parameters\n        ----------\n        dtype : data type, or dict of column name -> data type\n            Use a numpy.dtype or Python type to cast entire pandas object to\n            the same type. Alternatively, use {col: dtype, ...}, where col is a\n            column label and dtype is a numpy.dtype or Python type to cast one\n            or more of the DataFrame's columns to column-specific types.\n        copy : bool, default True\n            Return a copy when ``copy=True`` (be very careful setting\n            ``copy=False`` as changes to values then may propagate to other\n            pandas objects).\n        errors : {'raise', 'ignore'}, default 'raise'\n            Control raising of exceptions on invalid data for provided dtype.\n\n            - ``raise`` : allow exceptions to be raised\n            - ``ignore`` : suppress exceptions. On error return original object\n\n            .. versionadded:: 0.20.0\n\n        kwargs : keyword arguments to pass on to the constructor\n\n        Returns\n        -------\n        casted : same type as caller\n\n        See Also\n        --------\n        to_datetime : Convert argument to datetime.\n        to_timedelta : Convert argument to timedelta.\n        to_numeric : Convert argument to a numeric type.\n        numpy.ndarray.astype : Cast a numpy array to a specified type.\n\n        Examples\n        --------\n        >>> ser = pd.Series([1, 2], dtype='int32')\n        >>> ser\n        0    1\n        1    2\n        dtype: int32\n        >>> ser.astype('int64')\n        0    1\n        1    2\n        dtype: int64\n\n        Convert to categorical type:\n\n        >>> ser.astype('category')\n        0    1\n        1    2\n        dtype: category\n        Categories (2, int64): [1, 2]\n\n        Convert to ordered categorical type with custom ordering:\n\n        >>> cat_dtype = pd.api.types.CategoricalDtype(\n        ...                     categories=[2, 1], ordered=True)\n        >>> ser.astype(cat_dtype)\n        0    1\n        1    2\n        dtype: category\n        Categories (2, int64): [2 < 1]\n\n        Note that using ``copy=False`` and changing data on a new\n        pandas object may propagate changes:\n\n        >>> s1 = pd.Series([1,2])\n        >>> s2 = s1.astype('int64', copy=False)\n        >>> s2[0] = 10\n        >>> s1  # note that s1[0] has changed too\n        0    10\n        1     2\n        dtype: int64\n        "
    if is_dict_like(dtype):
        if (self.ndim == 1):
            if ((len(dtype) > 1) or (self.name not in dtype)):
                raise KeyError('Only the Series name can be used for the key in Series dtype mappings.')
            new_type = dtype[self.name]
            return self.astype(new_type, copy, errors, **kwargs)
        elif (self.ndim > 2):
            raise NotImplementedError('astype() only accepts a dtype arg of type dict when invoked on Series and DataFrames. A single dtype must be specified when invoked on a Panel.')
        for col_name in dtype.keys():
            if (col_name not in self):
                raise KeyError('Only a column name can be used for the key in a dtype mappings argument.')
        results = []
        for (col_name, col) in self.iteritems():
            if (col_name in dtype):
                results.append(col.astype(dtype[col_name], copy=copy))
            else:
                results.append(results.append((col.copy() if copy else col)))
    elif (is_extension_array_dtype(dtype) and (self.ndim > 1)):
        results = (self.iloc[:, i].astype(dtype, copy=copy) for i in range(len(self.columns)))
    else:
        new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors, **kwargs)
        return self._constructor(new_data).__finalize__(self)
    result = pd.concat(results, axis=1, copy=False)
    result.columns = self.columns
    return result
Cast a pandas object to a specified dtype ``dtype``.

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

    .. versionadded:: 0.20.0

kwargs : keyword arguments to pass on to the constructor

Returns
-------
casted : same type as caller

See Also
--------
to_datetime : Convert argument to datetime.
to_timedelta : Convert argument to timedelta.
to_numeric : Convert argument to a numeric type.
numpy.ndarray.astype : Cast a numpy array to a specified type.

Examples
--------
>>> ser = pd.Series([1, 2], dtype='int32')
>>> ser
0    1
1    2
dtype: int32
>>> ser.astype('int64')
0    1
1    2
dtype: int64

Convert to categorical type:

>>> ser.astype('category')
0    1
1    2
dtype: category
Categories (2, int64): [1, 2]

Convert to ordered categorical type with custom ordering:

>>> cat_dtype = pd.api.types.CategoricalDtype(
...                     categories=[2, 1], ordered=True)
>>> ser.astype(cat_dtype)
0    1
1    2
dtype: category
Categories (2, int64): [2 < 1]

Note that using ``copy=False`` and changing data on a new
pandas object may propagate changes:

>>> s1 = pd.Series([1,2])
>>> s2 = s1.astype('int64', copy=False)
>>> s2[0] = 10
>>> s1  # note that s1[0] has changed too
0    10
1     2
dtype: int64
def astype(self, dtype, copy=True, errors='raise', **kwargs):
    "\n        Cast a pandas object to a specified dtype ``dtype``.\n\n        Parameters\n        ----------\n        dtype : data type, or dict of column name -> data type\n            Use a numpy.dtype or Python type to cast entire pandas object to\n            the same type. Alternatively, use {col: dtype, ...}, where col is a\n            column label and dtype is a numpy.dtype or Python type to cast one\n            or more of the DataFrame's columns to column-specific types.\n        copy : bool, default True\n            Return a copy when ``copy=True`` (be very careful setting\n            ``copy=False`` as changes to values then may propagate to other\n            pandas objects).\n        errors : {'raise', 'ignore'}, default 'raise'\n            Control raising of exceptions on invalid data for provided dtype.\n\n            - ``raise`` : allow exceptions to be raised\n            - ``ignore`` : suppress exceptions. On error return original object\n\n            .. versionadded:: 0.20.0\n\n        kwargs : keyword arguments to pass on to the constructor\n\n        Returns\n        -------\n        casted : same type as caller\n\n        See Also\n        --------\n        to_datetime : Convert argument to datetime.\n        to_timedelta : Convert argument to timedelta.\n        to_numeric : Convert argument to a numeric type.\n        numpy.ndarray.astype : Cast a numpy array to a specified type.\n\n        Examples\n        --------\n        >>> ser = pd.Series([1, 2], dtype='int32')\n        >>> ser\n        0    1\n        1    2\n        dtype: int32\n        >>> ser.astype('int64')\n        0    1\n        1    2\n        dtype: int64\n\n        Convert to categorical type:\n\n        >>> ser.astype('category')\n        0    1\n        1    2\n        dtype: category\n        Categories (2, int64): [1, 2]\n\n        Convert to ordered categorical type with custom ordering:\n\n        >>> cat_dtype = pd.api.types.CategoricalDtype(\n        ...                     categories=[2, 1], ordered=True)\n        >>> ser.astype(cat_dtype)\n        0    1\n        1    2\n        dtype: category\n        Categories (2, int64): [2 < 1]\n\n        Note that using ``copy=False`` and changing data on a new\n        pandas object may propagate changes:\n\n        >>> s1 = pd.Series([1,2])\n        >>> s2 = s1.astype('int64', copy=False)\n        >>> s2[0] = 10\n        >>> s1  # note that s1[0] has changed too\n        0    10\n        1     2\n        dtype: int64\n        "
    if is_dict_like(dtype):
        if (self.ndim == 1):
            if ((len(dtype) > 1) or (self.name not in dtype)):
                raise KeyError('Only the Series name can be used for the key in Series dtype mappings.')
            new_type = dtype[self.name]
            return self.astype(new_type, copy, errors, **kwargs)
        elif (self.ndim > 2):
            raise NotImplementedError('astype() only accepts a dtype arg of type dict when invoked on Series and DataFrames. A single dtype must be specified when invoked on a Panel.')
        for col_name in dtype.keys():
            if (col_name not in self):
                raise KeyError('Only a column name can be used for the key in a dtype mappings argument.')
        results = []
        for (col_name, col) in self.iteritems():
            if (col_name in dtype):
                results.append(col.astype(dtype[col_name], copy=copy))
            else:
                results.append(results.append((col.copy() if copy else col)))
    elif (is_extension_array_dtype(dtype) and (self.ndim > 1)):
        results = (self.iloc[:, i].astype(dtype, copy=copy) for i in range(len(self.columns)))
    else:
        new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors, **kwargs)
        return self._constructor(new_data).__finalize__(self)
    result = pd.concat(results, axis=1, copy=False)
    result.columns = self.columns
    return result