modin.pandas.Series.squeeze¶
- Series.squeeze(axis=None) Union[Series, Scalar][source]¶
Squeeze 1 dimensional axis objects into scalars.
Series or DataFrames with a single element are squeezed to a scalar. DataFrames with a single column or a single row are squeezed to a Series. Otherwise, the object is unchanged.
This method is most useful when you don’t know if your object is a Series or DataFrame, but you do know it has just a single column. In that case you can safely call squeeze to ensure you have a Series.
- Parameters:
axis ({0 or 'index', 1 or 'columns', None}, default None) – A specific axis to squeeze. By default, all length-1 axes are squeezed. For Series this parameter is unused and defaults to None.
- Returns:
The projection after squeezing axis or all the axes.
- Return type:
See also
Series.ilocInteger-location based indexing for selecting scalars.
DataFrame.ilocInteger-location based indexing for selecting Series.
Series.to_frameInverse of DataFrame.squeeze for a single-column DataFrame.
Examples
Slicing might produce a Series with a single value:
Squeezing objects with more than one value in every axis does nothing:
Squeezing is even more effective when used with DataFrames.
Slicing a single column will produce a DataFrame with the columns having only one value:
So the columns can be squeezed down, resulting in a Series:
Slicing a single row from a single column will produce a single scalar DataFrame:
Squeezing the rows produces a single scalar Series:
Squeezing all axes will project directly into a scalar: