pandas.SparseDtype.construct_from_string

classmethod SparseDtype.construct_from_string(string)[source]

Construct a SparseDtype from a string form.

Parameters:
string : str

Can take the following forms.

string dtype ================ ============================ ‘int’ SparseDtype[np.int64, 0] ‘Sparse’ SparseDtype[np.float64, nan] ‘Sparse[int]’ SparseDtype[np.int64, 0] ‘Sparse[int, 0]’ SparseDtype[np.int64, 0] ================ ============================

It is not possible to specify non-default fill values with a string. An argument like 'Sparse[int, 1]' will raise a TypeError because the default fill value for integers is 0.

Returns:
SparseDtype
Scroll To Top