pandas.unique

pandas.unique(values)
基于哈希表的唯一性,唯一值按出现顺序返回。

Parameters

values 一维数组

Example

  1. import pandas as pd
  2. df = pd.DataFrame({'site':['google', 'baidu', 'wiki', 'pandas'],
  3. 'age':[18, 39, 22, 45],
  4. 'price': [1.0, 2.0, 3.0, 4.0],
  5. 'color': ['red', 'black', None, 'red']}, index=['first', 'second', 'third', 'forth'])
  6. pd.unique(df.loc[:, 'color'])
  7. ---------------------------------------------------
  8. array(['red', 'black', None], dtype=object)

Example

  1. import pandas as pd
  2. df = pd.DataFrame({'site':['google', 'baidu', 'wiki', 'pandas'],
  3. 'age':[18, 39, 22, 45],
  4. 'price': [1.0, 2.0, 3.0, 4.0],
  5. 'color': ['red', 'black', None, 'red']}, index=['first', 'first', 'second', 'second'])
  6. pd.unique(df.index)
  7. --------------------------------------------
  8. array(['first', 'second'], dtype=object)