pandas/astype

Change Data Type

Convert Series to specified dtype

pandas
dtype
convert

Command

df.astype

Explanation

df.astype() is used to change the datatype of columns.

Examples

Convert column to integer

df["col"] = df["col"].astype(int)

Convert multiple columns at once

df = df.astype({"col1": float, "col2": "string"})