Pandas unique(~)
方法返回輸入數組的唯一值。返回值的順序遵循其在輸入數組中的原始順序。
參數
1. values
| array-like
輸入數組。通常這是一個標準列表、一個係列或一個 NumPy 數組。
返回值
返回類型取決於 values
的類型:
輸入類型 |
返回類型 |
---|---|
Index |
Index |
Categorical |
Categorical |
Array-like |
numpy 數組 |
例子
基本用法
要查找係列的唯一值:
s = pd.Series([7,6,5,7])
pd.unique(s)
array([7, 6, 5])
請注意以下事項:
-
唯一值尊重原始順序
-
由於輸入是列表,因此返回類型是 Numpy 數組
獨特的元組
正如您所期望的,當至少一對項目不匹配時,一對元組被認為是唯一的:
s = pd.Series([("A","B"),("B","B"),("A","B")])
pd.unique(s)
array([('A', 'B'), ('B', 'B')], dtype=object)
相關用法
- Python NumPy unique方法用法及代碼示例
- Python unittest.mock.AsyncMock.assert_awaited_once_with用法及代碼示例
- Python unittest.TestCase.assertWarnsRegex用法及代碼示例
- Python unittest.mock.Mock.__class__用法及代碼示例
- Python unittest.TestCase.assertRaisesRegex用法及代碼示例
- Python unittest.mock.call用法及代碼示例
- Python unittest.mock.Mock.method_calls用法及代碼示例
- Python unittest.mock.Mock.call_args_list用法及代碼示例
- Python unittest.mock.AsyncMock.assert_any_await用法及代碼示例
- Python unittest.mock.Mock.assert_called用法及代碼示例
- Python unittest.TestCase.assertRaises用法及代碼示例
- Python unittest.TestCase.tearDownClass用法及代碼示例
- Python unittest.mock.Mock.assert_not_called用法及代碼示例
- Python unittest.IsolatedAsyncioTestCase用法及代碼示例
- Python unittest.TestCase.setUpClass用法及代碼示例
- Python unittest.mock.Mock.mock_calls用法及代碼示例
- Python unittest.mock.Mock.call_args用法及代碼示例
- Python unittest.mock.Mock.assert_has_calls用法及代碼示例
- Python unittest.mock.AsyncMock.assert_awaited_with用法及代碼示例
- Python unittest.mock.Mock.configure_mock用法及代碼示例
- Python unittest.mock.Mock.called用法及代碼示例
- Python unittest.mock.Mock.side_effect用法及代碼示例
- Python unittest.mock.Mock.assert_called_once_with用法及代碼示例
- Python unittest.mock.AsyncMock.assert_has_awaits用法及代碼示例
- Python unittest.mock.AsyncMock.assert_awaited_once用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Pandas | unique method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。