Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.median#

DataFrame.median(axis=0,skipna=True,numeric_only=False,**kwargs)[source]#

Return the median of the values over the requested axis.

Parameters:
axis{index (0), columns (1)}

Axis for the function to be applied on.ForSeries this parameter is unused and defaults to 0.

For DataFrames, specifyingaxis=None will apply the aggregationacross both axes.

Added in version 2.0.0.

skipnabool, default True

Exclude NA/null values when computing the result.

numeric_onlybool, default False

Include only float, int, boolean columns. Not implemented for Series.

**kwargs

Additional keyword arguments to be passed to the function.

Returns:
Series or scalar

Examples

>>>s=pd.Series([1,2,3])>>>s.median()2.0

With a DataFrame

>>>df=pd.DataFrame({'a':[1,2],'b':[2,3]},index=['tiger','zebra'])>>>df       a   btiger  1   2zebra  2   3>>>df.median()a   1.5b   2.5dtype: float64

Using axis=1

>>>df.median(axis=1)tiger   1.5zebra   2.5dtype: float64

In this case,numeric_only should be set toTrueto avoid getting an error.

>>>df=pd.DataFrame({'a':[1,2],'b':['T','Z']},...index=['tiger','zebra'])>>>df.median(numeric_only=True)a   1.5dtype: float64

[8]ページ先頭

©2009-2025 Movatter.jp