Skip to content

LazyColumn.astype

astype

astype(dtype: str | DuckDBPyType) -> LazyColumn

Converts the type of the values in this column to the specified type.

Parameters:

Name Type Description Default
dtype str | DuckDBPyType

The desired type for conversion. Can be a string (e.g., "INTEGER", "VARCHAR") or a DuckDBPyType object.

required

Returns:

Name Type Description
LazyColumn LazyColumn

A new LazyColumn with values converted to the specified type.

Examples:

print(df.head())
#    col1 my_column_to_test
# 0     1                "1"
# 1     2                "2"
# 2     3               None
# 3     4               "10"
# 4     5               "20"

# Converting to integer
df["my_column_to_test"].astype("INTEGER")
# [1, 2, None, 10, 20]

# Converting to string
df["my_column_to_test"].astype("VARCHAR")
# ["1", "2", None, "10", "20"]