pandas.uniqueの例
Pandas Unique Example
-
パンダ。
個性的(( 値 ) [ソース]
-
ハッシュテーブルベースのユニーク。ユニークは出現順に返されます。これはソートされません。
numpy.uniqueよりも大幅に高速です。 NA値を含みます。
- パラメーター
-
- 値 :1D配列のような
- 戻り値
-
- numpy.ndarrayまたはExtensionArray
-
リターンは次のようになります。
インデックス:入力がインデックスの場合
カテゴリ:入力がカテゴリdtypeの場合
ndarray:入力がSeries / ndarrayの場合
numpy.ndarrayまたはExtensionArrayを返します。
も参照してください
-
Index.unique
-
インデックスから一意の値を返します。
-
Series.unique
-
Seriesオブジェクトの一意の値を返します。
例
>>> pd.unique(pd.Series([2, 1, 3, 3])) array([2, 1, 3])
>>> pd.unique(pd.Series([2] + [1] * 5)) array([2, 1])
>>> pd.unique(pd.Series([pd.Timestamp('20160101'), ... pd.Timestamp('20160101')])) array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
>>> pd.unique(pd.Series([pd.Timestamp('20160101', tz='US/Eastern'), ... pd.Timestamp('20160101', tz='US/Eastern')])) array([Timestamp('2016-01-01 00:00:00-0500', tz='US/Eastern')], dtype=object)
>>> pd.unique(pd.Index([pd.Timestamp('20160101', tz='US/Eastern'), ... pd.Timestamp('20160101', tz='US/Eastern')])) DatetimeIndex(['2016-01-01 00:00:00-05:00'], ... dtype='datetime64[ns, US/Eastern]', freq=None)
>>> pd.unique(list('baabc')) array(['b', 'a', 'c'], dtype=object)
順序付けされていないカテゴリは、出現順にカテゴリを返します。
>>> pd.unique(pd.Series(pd.Categorical(list('baabc')))) [b, a, c] Categories (3, object): [b, a, c]
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'), ... categories=list('abc')))) [b, a, c] Categories (3, object): [b, a, c]
順序付けられたカテゴリは、カテゴリの順序を保持します。
>>> pd.unique(pd.Series(pd.Categorical(list('baabc'), ... categories=list('abc'), ... ordered=True))) [b, a, c] Categories (3, object): [a < b < c]
タプルの配列
>>> pd.unique([('a', 'b'), ('b', 'a'), ('a', 'c'), ('b', 'a')]) array([('a', 'b'), ('b', 'a'), ('a', 'c')], dtype=object)