pyspark.pandas.Series.astype¶
-
Series.
astype
(dtype: Union[str, type, numpy.dtype, pandas.core.dtypes.base.ExtensionDtype]) → IndexOpsLike¶ Cast a pandas-on-Spark object to a specified dtype
dtype
.- Parameters
- dtypedata type
Use a numpy.dtype or Python type to cast entire pandas object to the same type.
- Returns
- castedsame type as caller
See also
to_datetime
Convert argument to datetime.
Examples
>>> ser = ps.Series([1, 2], dtype='int32') >>> ser 0 1 1 2 dtype: int32
>>> ser.astype('int64') 0 1 1 2 dtype: int64
>>> ser.rename("a").to_frame().set_index("a").index.astype('int64') Int64Index([1, 2], dtype='int64', name='a')