DataFrameastype
DataFrame.astype is a pandas method used to convert the data type of one or more columns in a DataFrame. It can accept a single dtype to apply to all columns or a dictionary mapping column names to dtypes, enabling per-column casting. For example, a DataFrame df can be cast with df.astype({'A': 'float64', 'B': 'Int64'}) to convert column A to float64 and column B to the nullable integer type Int64.
The method returns a new DataFrame by default, with copy semantics controlled by the copy parameter. If
Error handling is controlled by the errors parameter, which accepts 'raise' (the default) to raise if a
Astype supports numpy dtypes like 'int64', 'float64', 'bool', and object types, as well as pandas extension dtypes
Note that for converting strings to datetimes, casting with astype may not reliably parse arbitrary date formats;