w3resource

Pandas Series: squeeze() function

Squeeze 1 dimensional axis objects into scalars

Squeeze 1 dimensional axis Series or DataFrames 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.

Syntax:

Series.squeeze(self, axis=None)
Pandas Series squeeze image
Name Description Type/Default Value Required / Optional
axis A specific axis to squeeze. By default, all length-1 axes are squeezed. {0 or ‘index’, 1 or ‘columns’, None}
Default Value: None
Required

Returns: DataFrame, Series, or scalar - The projection after squeezing axis or all the axes.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts