DataFrame.
astype
Cast a pandas-on-Spark object to a specified dtype dtype.
dtype
Use a numpy.dtype or Python type to cast entire pandas-on-Spark 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.
See also
to_datetime
Convert argument to datetime.
Examples
>>> df = ps.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3]}, dtype='int64') >>> df a b 0 1 1 1 2 2 2 3 3
Convert to float type:
>>> df.astype('float') a b 0 1.0 1.0 1 2.0 2.0 2 3.0 3.0
Convert to int64 type back:
>>> df.astype('int64') a b 0 1 1 1 2 2 2 3 3
Convert column a to float type:
>>> df.astype({'a': float}) a b 0 1.0 1 1 2.0 2 2 3.0 3