DataFrame.median

DataFrame.median(numeric_only: bool | None = None) Series

Return the median value for each numeric column

Parameters

numeric_only: {True, False, None} Default is None

Which datatype to be returned - True: Returns all values as float64, NaN/NaT values are removed - None: Returns all values as the same dtype where possible, NaN/NaT are removed - False: Returns all values as the same dtype where possible, NaN/NaT are preserved

Returns

pandas.Series

median value for each numeric column

See Also

:pandas_api_docs:`pandas.DataFrame.median`

Examples

>>> from tests import OPENSEARCH_TEST_CLIENT
>>> df = oml.DataFrame(OPENSEARCH_TEST_CLIENT, 'flights', columns=["AvgTicketPrice", "Cancelled", "dayOfWeek", "timestamp", "DestCountry"])
>>> df.median() 
AvgTicketPrice                          640.363
Cancelled                                 False
dayOfWeek                                     3
timestamp         2018-01-21 23:54:06.624776611
dtype: object
>>> df.median(numeric_only=True) 
AvgTicketPrice    640.362667
Cancelled           0.000000
dayOfWeek           3.000000
dtype: float64
>>> df.median(numeric_only=False) 
AvgTicketPrice                          640.387
Cancelled                                 False
dayOfWeek                                     3
timestamp         2018-01-21 23:54:06.624776611
DestCountry                                 NaN
dtype: object