当前位置: 首页>>代码示例>>Python>>正文


Python pandas.unique方法代码示例

本文整理汇总了Python中pandas.unique方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.unique方法的具体用法?Python pandas.unique怎么用?Python pandas.unique使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas的用法示例。


在下文中一共展示了pandas.unique方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_timedelta64_dtype_array_returned

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_timedelta64_dtype_array_returned(self):
        # GH 9431
        expected = np.array([31200, 45678, 10000], dtype='m8[ns]')

        td_index = pd.to_timedelta([31200, 45678, 31200, 10000, 45678])
        result = algos.unique(td_index)
        tm.assert_numpy_array_equal(result, expected)
        assert result.dtype == expected.dtype

        s = Series(td_index)
        result = algos.unique(s)
        tm.assert_numpy_array_equal(result, expected)
        assert result.dtype == expected.dtype

        arr = s.values
        result = algos.unique(arr)
        tm.assert_numpy_array_equal(result, expected)
        assert result.dtype == expected.dtype 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_algos.py

示例2: test_first_nan_kept

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_first_nan_kept(self):
        # GH 22295
        # create different nans from bit-patterns:
        bits_for_nan1 = 0xfff8000000000001
        bits_for_nan2 = 0x7ff8000000000001
        NAN1 = struct.unpack("d", struct.pack("=Q", bits_for_nan1))[0]
        NAN2 = struct.unpack("d", struct.pack("=Q", bits_for_nan2))[0]
        assert NAN1 != NAN1
        assert NAN2 != NAN2
        for el_type in [np.float64, np.object]:
            a = np.array([NAN1, NAN2], dtype=el_type)
            result = pd.unique(a)
            assert result.size == 1
            # use bit patterns to identify which nan was kept:
            result_nan_bits = struct.unpack("=Q",
                                            struct.pack("d", result[0]))[0]
            assert result_nan_bits == bits_for_nan1 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_algos.py

示例3: test_unpivot

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_unpivot():
    frame = pd.DataFrame({'x': range(10), 'y': range(10), 'z': range(10)})
    df = unpivot_frame(frame, var_name='foo', value_name='bar')
    assert list(df.columns) == ['index', 'foo', 'bar']
    assert set(pd.unique(df['foo'])) == {'x', 'y', 'z'}

    df = unpivot_frame(frame, x='x')
    assert list(df.columns) == ['x', 'variable', 'value']
    assert set(pd.unique(df['variable'])) == {'y', 'z'}

    df = unpivot_frame(frame, y='y')
    assert list(df.columns) == ['index', 'variable', 'value']
    assert set(pd.unique(df['variable'])) == {'y'}

    df = unpivot_frame(frame, y=('y', 'z'))
    assert list(df.columns) == ['index', 'variable', 'value']
    assert set(pd.unique(df['variable'])) == {'y', 'z'}

    df = unpivot_frame(frame, x=('x', 'y'), y='z')
    assert list(df.columns) == ['x', 'y', 'variable', 'value']
    assert set(pd.unique(df['variable'])) == {'z'} 
开发者ID:altair-viz,项目名称:pdvega,代码行数:23,代码来源:test_utils.py

示例4: test_qcut_binning_issues

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_qcut_binning_issues(self, datapath):
        # #1978, 1979
        cut_file = datapath(os.path.join('reshape', 'data', 'cut_data.csv'))
        arr = np.loadtxt(cut_file)

        result = qcut(arr, 20)

        starts = []
        ends = []
        for lev in np.unique(result):
            s = lev.left
            e = lev.right
            assert s != e

            starts.append(float(s))
            ends.append(float(e))

        for (sp, sn), (ep, en) in zip(zip(starts[:-1], starts[1:]),
                                      zip(ends[:-1], ends[1:])):
            assert sp < sn
            assert ep < en
            assert ep <= sn 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_tile.py

示例5: test_datetime64_dtype_array_returned

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_datetime64_dtype_array_returned(self):
        # GH 9431
        expected = np_array_datetime64_compat(
            ['2015-01-03T00:00:00.000000000+0000',
             '2015-01-01T00:00:00.000000000+0000'],
            dtype='M8[ns]')

        dt_index = pd.to_datetime(['2015-01-03T00:00:00.000000000+0000',
                                   '2015-01-01T00:00:00.000000000+0000',
                                   '2015-01-01T00:00:00.000000000+0000'])
        result = algos.unique(dt_index)
        tm.assert_numpy_array_equal(result, expected)
        assert result.dtype == expected.dtype

        s = Series(dt_index)
        result = algos.unique(s)
        tm.assert_numpy_array_equal(result, expected)
        assert result.dtype == expected.dtype

        arr = s.values
        result = algos.unique(arr)
        tm.assert_numpy_array_equal(result, expected)
        assert result.dtype == expected.dtype 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:test_algos.py

示例6: test_cut_duplicates_bin

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_cut_duplicates_bin(kwargs, msg):
    # see gh-20947
    bins = [0, 2, 4, 6, 10, 10]
    values = Series(np.array([1, 3, 5, 7, 9]), index=["a", "b", "c", "d", "e"])

    if msg is not None:
        with pytest.raises(ValueError, match=msg):
            cut(values, bins, **kwargs)
    else:
        result = cut(values, bins, **kwargs)
        expected = cut(values, pd.unique(bins))
        tm.assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_cut.py

示例7: test_ints

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_ints(self):
        arr = np.random.randint(0, 100, size=50)

        result = algos.unique(arr)
        assert isinstance(result, np.ndarray) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_algos.py

示例8: test_objects

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_objects(self):
        arr = np.random.randint(0, 100, size=50).astype('O')

        result = algos.unique(arr)
        assert isinstance(result, np.ndarray) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_algos.py

示例9: test_object_refcount_bug

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_object_refcount_bug(self):
        lst = ['A', 'B', 'C', 'D', 'E']
        for i in range(1000):
            len(algos.unique(lst)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_algos.py

示例10: test_on_index_object

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_on_index_object(self):

        mindex = pd.MultiIndex.from_arrays([np.arange(5).repeat(5), np.tile(
            np.arange(5), 5)])
        expected = mindex.values
        expected.sort()

        mindex = mindex.repeat(2)

        result = pd.unique(mindex)
        result.sort()

        tm.assert_almost_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_algos.py

示例11: test_uint64_overflow

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_uint64_overflow(self):
        s = Series([1, 2, 2**63, 2**63], dtype=np.uint64)
        exp = np.array([1, 2, 2**63], dtype=np.uint64)
        tm.assert_numpy_array_equal(algos.unique(s), exp) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_algos.py

示例12: test_nan_in_object_array

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_nan_in_object_array(self):
        duplicated_items = ['a', np.nan, 'c', 'c']
        result = pd.unique(duplicated_items)
        expected = np.array(['a', np.nan, 'c'], dtype=object)
        tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_algos.py

示例13: test_datetime64tz_aware

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_datetime64tz_aware(self):
        # GH 15939

        result = Series(
            Index([Timestamp('20160101', tz='US/Eastern'),
                   Timestamp('20160101', tz='US/Eastern')])).unique()
        expected = DatetimeArray._from_sequence(np.array([
            Timestamp('2016-01-01 00:00:00-0500', tz="US/Eastern")
        ]))
        tm.assert_extension_array_equal(result, expected)

        result = Index([Timestamp('20160101', tz='US/Eastern'),
                        Timestamp('20160101', tz='US/Eastern')]).unique()
        expected = DatetimeIndex(['2016-01-01 00:00:00'],
                                 dtype='datetime64[ns, US/Eastern]', freq=None)
        tm.assert_index_equal(result, expected)

        result = pd.unique(
            Series(Index([Timestamp('20160101', tz='US/Eastern'),
                          Timestamp('20160101', tz='US/Eastern')])))
        expected = DatetimeArray._from_sequence(np.array([
            Timestamp('2016-01-01', tz="US/Eastern"),
        ]))
        tm.assert_extension_array_equal(result, expected)

        result = pd.unique(Index([Timestamp('20160101', tz='US/Eastern'),
                                  Timestamp('20160101', tz='US/Eastern')]))
        expected = DatetimeIndex(['2016-01-01 00:00:00'],
                                 dtype='datetime64[ns, US/Eastern]', freq=None)
        tm.assert_index_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:32,代码来源:test_algos.py

示例14: test_tuple_with_strings

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_tuple_with_strings(self, arg, expected):
        # see GH 17108
        result = pd.unique(arg)
        tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_algos.py

示例15: test_obj_none_preservation

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import unique [as 别名]
def test_obj_none_preservation(self):
        # GH 20866
        arr = np.array(['foo', None], dtype=object)
        result = pd.unique(arr)
        expected = np.array(['foo', None], dtype=object)

        tm.assert_numpy_array_equal(result, expected, strict_nan=True) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_algos.py


注:本文中的pandas.unique方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。