Pandas DataFrame: astype() function
DataFrame - astype() function
The astype() function is used to cast a pandas object to a specified dtype dtype.
Syntax:
DataFrame.astype(self, dtype, copy=True, errors='raise', **kwargs)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
dtype | 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. | data type, or dict of column name -> data type | Required |
copy | Return a copy when copy=True (be very careful setting copy=False as changes to values then may propagate to other pandas objects). | bool Default Value: True |
Required |
errors | Control raising of exceptions on invalid data for provided dtype.
|
{‘raise’, ‘ignore’} Default Value: ‘raise’ |
Required |
kwargs | keyword arguments to pass on to the constructor | Required |
Returns: numpy.ndarray
The astype of the DataFrame.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - empty() function
Next: DataFrame - infer_objects() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework