「Python」pandas.Seriesのmode()でシリーズのモードを返す
環境
pandas 1.4.2
PyCharm 2021.3.3
構文
Series.mode(dropna=True)
シリーズのモードを返します。
モードは、最も頻繁に表示される値です。 複数のモードがあります。
値が1つだけ返される場合でも、常にSeriesを返します。
パラメーター
dropnabool、デフォルトはTrue
NaN/NaTの数を考慮しないでください。
戻り値 シリーズ
ソートされた順序でのシリーズのモード。
pandas.Seriesからmode()を呼ぶとpandas.Seriesが返ります
使用例
# coding: utf-8
import pandas as pd
cft = pd.Series(['S', 'S', 'T', 'R'])
print("結果1")
print(cft)
print("結果2")
print(cft.mode())
print("結果3")
print(type(cft.mode()))
実行結果
結果1 0 S 1 S 2 T 3 R dtype: object 結果2 0 S dtype: object 結果3 <class 'pandas.core.series.Series'>