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


Python Dataset.aggregate方法代码示例

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


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

示例1: test_dataset_2D_aggregate_partial_hm

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_dataset_2D_aggregate_partial_hm(self):
     array = np.random.rand(11, 11)
     dataset = Dataset({'x':self.xs, 'y':self.y_ints, 'z': array},
                       kdims=['x', 'y'], vdims=['z'])
     self.assertEqual(dataset.aggregate(['x'], np.mean),
                      Dataset({'x':self.xs, 'z': np.mean(array, axis=0)},
                              kdims=['x'], vdims=['z']))
开发者ID:RafalSkolasinski,项目名称:holoviews,代码行数:9,代码来源:testdataset.py

示例2: test_dataset_2D_aggregate_spread_fn_with_duplicates

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_dataset_2D_aggregate_spread_fn_with_duplicates(self):
     dataset = Dataset({'x': np.array([0, 0, 1, 1]), 'y': np.array([0, 1, 2, 3]),
                        'z': np.array([1, 2, 3, 4])},
                       kdims=['x', 'y'], vdims=['z'])
     agg = dataset.aggregate('x', function=np.mean, spreadfn=np.var)
     self.assertEqual(agg, Dataset({'x': np.array([0, 1]), 'z': np.array([1.5, 3.5]),
                                    'z_var': np.array([0.25, 0.25])},
                                   kdims=['x'], vdims=['z', 'z_var']))
开发者ID:basnijholt,项目名称:holoviews,代码行数:10,代码来源:base.py

示例3: test_dataset_empty_aggregate_with_spreadfn

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_dataset_empty_aggregate_with_spreadfn(self):
     dataset = Dataset([], kdims=self.kdims, vdims=self.vdims)
     aggregated = Dataset([], kdims=self.kdims[:1], vdims=[d for vd in self.vdims for d in [vd, vd+'_std']])
     self.compare_dataset(dataset.aggregate(['Gender'], np.mean, np.std), aggregated)
开发者ID:basnijholt,项目名称:holoviews,代码行数:6,代码来源:base.py

示例4: test_dataset_empty_aggregate

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_dataset_empty_aggregate(self):
     dataset = Dataset([], kdims=self.kdims, vdims=self.vdims)
     aggregated = Dataset([], kdims=self.kdims[:1], vdims=self.vdims)
     self.compare_dataset(dataset.aggregate(['Gender'], np.mean), aggregated)
开发者ID:basnijholt,项目名称:holoviews,代码行数:6,代码来源:base.py

示例5: test_dataset_2D_aggregate_partial_ht

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_dataset_2D_aggregate_partial_ht(self):
     dataset = Dataset({'x':self.xs, 'y':self.ys, 'z':self.zs},
                       kdims=['x', 'y'], vdims=['z'])
     reduced = Dataset({'x':self.xs, 'z':self.zs},
                       kdims=['x'], vdims=['z'])
     self.assertEqual(dataset.aggregate(['x'], np.mean), reduced)
开发者ID:basnijholt,项目名称:holoviews,代码行数:8,代码来源:base.py

示例6: test_dataset_aggregate_string_types_size

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_dataset_aggregate_string_types_size(self):
     ds = Dataset({'Gender':['M', 'M'], 'Weight':[20, 10], 'Name':['Peter', 'Matt']},
                          kdims='Gender', vdims=['Weight', 'Name'])
     aggregated = Dataset({'Gender': ['M'], 'Weight': [2], 'Name': [2]},
                          kdims='Gender', vdims=['Weight', 'Name'])
     self.compare_dataset(ds.aggregate(['Gender'], np.size), aggregated)
开发者ID:basnijholt,项目名称:holoviews,代码行数:8,代码来源:base.py

示例7: HeterogeneousColumnTests

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]

#.........这里部分代码省略.........
                                 kdims=['x'], vdims=['y'])
        self.assertEqual(dataset.sort('y'), dataset_sorted)

    def test_dataset_sort_string_ht(self):
        dataset_sorted = Dataset({'Gender':['F', 'M', 'M'], 'Age':[12, 10, 16],
                                  'Weight':[10,15,18], 'Height':[0.8,0.8,0.6]},
                                 kdims=self.kdims, vdims=self.vdims)
        self.assertEqual(self.table.sort(), dataset_sorted)

    def test_dataset_sample_ht(self):
        samples = self.dataset_ht.sample([0, 5, 10]).dimension_values('y')
        self.assertEqual(samples, np.array([0, 0.5, 1]))

    def test_dataset_reduce_ht(self):
        reduced = Dataset({'Age':self.age, 'Weight':self.weight, 'Height':self.height},
                          kdims=self.kdims[1:], vdims=self.vdims)
        self.assertEqual(self.table.reduce(['Gender'], np.mean), reduced)

    def test_dataset_1D_reduce_ht(self):
        self.assertEqual(self.dataset_ht.reduce('x', np.mean), np.float64(0.5))

    def test_dataset_2D_reduce_ht(self):
        reduced = Dataset({'Weight':[14.333333333333334], 'Height':[0.73333333333333339]},
                          kdims=[], vdims=self.vdims)
        self.assertEqual(self.table.reduce(function=np.mean), reduced)

    def test_dataset_2D_partial_reduce_ht(self):
        dataset = Dataset({'x':self.xs, 'y':self.ys, 'z':self.zs},
                          kdims=['x', 'y'], vdims=['z'])
        reduced = Dataset({'x':self.xs, 'z':self.zs},
                          kdims=['x'], vdims=['z'])
        self.assertEqual(dataset.reduce(['y'], np.mean), reduced)

    def test_dataset_2D_aggregate_spread_fn_with_duplicates(self):
        dataset = Dataset({'x': np.array([0, 0, 1, 1]), 'y': np.array([0, 1, 2, 3]),
                           'z': np.array([1, 2, 3, 4])},
                          kdims=['x', 'y'], vdims=['z'])
        agg = dataset.aggregate('x', function=np.mean, spreadfn=np.var)
        self.assertEqual(agg, Dataset({'x': np.array([0, 1]), 'z': np.array([1.5, 3.5]),
                                       'z_var': np.array([0.25, 0.25])},
                                      kdims=['x'], vdims=['z', 'z_var']))

    def test_dataset_aggregate_ht(self):
        aggregated = Dataset({'Gender':['M', 'F'], 'Weight':[16.5, 10], 'Height':[0.7, 0.8]},
                             kdims=self.kdims[:1], vdims=self.vdims)
        self.compare_dataset(self.table.aggregate(['Gender'], np.mean), aggregated)

    def test_dataset_aggregate_string_types(self):
        ds = Dataset({'Gender':['M', 'M'], 'Weight':[20, 10], 'Name':['Peter', 'Matt']},
                             kdims='Gender', vdims=['Weight', 'Name'])
        aggregated = Dataset({'Gender': ['M'], 'Weight': [15]},
                             kdims='Gender', vdims=['Weight'])
        self.compare_dataset(ds.aggregate(['Gender'], np.mean), aggregated)

    def test_dataset_aggregate_string_types_size(self):
        ds = Dataset({'Gender':['M', 'M'], 'Weight':[20, 10], 'Name':['Peter', 'Matt']},
                             kdims='Gender', vdims=['Weight', 'Name'])
        aggregated = Dataset({'Gender': ['M'], 'Weight': [2], 'Name': [2]},
                             kdims='Gender', vdims=['Weight', 'Name'])
        self.compare_dataset(ds.aggregate(['Gender'], np.size), aggregated)

    def test_dataset_aggregate_ht_alias(self):
        aggregated = Dataset({'gender':['M', 'F'], 'weight':[16.5, 10], 'height':[0.7, 0.8]},
                             kdims=self.alias_kdims[:1], vdims=self.alias_vdims)
        self.compare_dataset(self.alias_table.aggregate('Gender', np.mean), aggregated)
开发者ID:basnijholt,项目名称:holoviews,代码行数:69,代码来源:base.py

示例8: test_dataset_2D_aggregate_partial_hm

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_dataset_2D_aggregate_partial_hm(self):
     z_ints = [el**2 for el in self.y_ints]
     dataset = Dataset({'x':self.xs, 'y':self.y_ints, 'z':z_ints},
                       kdims=['x', 'y'], vdims=['z'])
     self.assertEqual(dataset.aggregate(['x'], np.mean),
                      Dataset({'x':self.xs, 'z':z_ints}, kdims=['x'], vdims=['z']))
开发者ID:basnijholt,项目名称:holoviews,代码行数:8,代码来源:base.py

示例9: test_aggregate_2d_with_spreadfn

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]
 def test_aggregate_2d_with_spreadfn(self):
     array = np.random.rand(10, 5)
     ds = Dataset((range(5), range(10), array), ['x', 'y'], 'z')
     agg = ds.aggregate('x', np.mean, np.std)
     example = Dataset((range(5), array.mean(axis=0), array.std(axis=0)), 'x', ['z', 'z_std'])
     self.assertEqual(agg, example)
开发者ID:basnijholt,项目名称:holoviews,代码行数:8,代码来源:base.py

示例10: HeterogeneousColumnTypes

# 需要导入模块: from holoviews import Dataset [as 别名]
# 或者: from holoviews.Dataset import aggregate [as 别名]

#.........这里部分代码省略.........
                                 kdims=['x'], vdims=['y'])
        self.assertEqual(dataset.sort('y'), dataset_sorted)

    def test_dataset_sort_string_ht(self):
        dataset_sorted = Dataset({'Gender':['F', 'M', 'M'], 'Age':[12, 10, 16],
                                  'Weight':[10,15,18], 'Height':[0.8,0.8,0.6]},
                                 kdims=self.kdims, vdims=self.vdims)
        self.assertEqual(self.table.sort(), dataset_sorted)

    def test_dataset_sample_ht(self):
        samples = self.dataset_ht.sample([0, 5, 10]).dimension_values('y')
        self.assertEqual(samples, np.array([0, 0.5, 1]))

    def test_dataset_reduce_ht(self):
        reduced = Dataset({'Age':self.age, 'Weight':self.weight, 'Height':self.height},
                          kdims=self.kdims[1:], vdims=self.vdims)
        self.assertEqual(self.table.reduce(['Gender'], np.mean), reduced)

    def test_dataset_1D_reduce_ht(self):
        self.assertEqual(self.dataset_ht.reduce('x', np.mean), np.float64(0.5))

    def test_dataset_2D_reduce_ht(self):
        reduced = Dataset({'Weight':[14.333333333333334], 'Height':[0.73333333333333339]},
                          kdims=[], vdims=self.vdims)
        self.assertEqual(self.table.reduce(function=np.mean), reduced)

    def test_dataset_2D_partial_reduce_ht(self):
        dataset = Dataset({'x':self.xs, 'y':self.ys, 'z':self.zs},
                          kdims=['x', 'y'], vdims=['z'])
        reduced = Dataset({'x':self.xs, 'z':self.zs},
                          kdims=['x'], vdims=['z'])
        self.assertEqual(dataset.reduce(['y'], np.mean), reduced)

    def test_column_aggregate_ht(self):
        aggregated = Dataset({'Gender':['M', 'F'], 'Weight':[16.5, 10], 'Height':[0.7, 0.8]},
                             kdims=self.kdims[:1], vdims=self.vdims)
        self.compare_dataset(self.table.aggregate(['Gender'], np.mean), aggregated)

    def test_dataset_2D_aggregate_partial_ht(self):
        dataset = Dataset({'x':self.xs, 'y':self.ys, 'z':self.zs},
                          kdims=['x', 'y'], vdims=['z'])
        reduced = Dataset({'x':self.xs, 'z':self.zs},
                          kdims=['x'], vdims=['z'])
        self.assertEqual(dataset.aggregate(['x'], np.mean), reduced)


    def test_dataset_groupby(self):
        group1 = {'Age':[10,16], 'Weight':[15,18], 'Height':[0.8,0.6]}
        group2 = {'Age':[12], 'Weight':[10], 'Height':[0.8]}
        grouped = HoloMap([('M', Dataset(group1, kdims=['Age'], vdims=self.vdims)),
                           ('F', Dataset(group2, kdims=['Age'], vdims=self.vdims))],
                          kdims=['Gender'])
        self.assertEqual(self.table.groupby(['Gender']), grouped)


    def test_dataset_add_dimensions_value_ht(self):
        table = self.dataset_ht.add_dimension('z', 1, 0)
        self.assertEqual(table.kdims[1], 'z')
        self.compare_arrays(table.dimension_values('z'), np.zeros(len(table)))

    def test_dataset_add_dimensions_values_ht(self):
        table = self.dataset_ht.add_dimension('z', 1, range(1,12))
        self.assertEqual(table.kdims[1], 'z')
        self.compare_arrays(table.dimension_values('z'), np.array(list(range(1,12))))

    # Indexing
开发者ID:RafalSkolasinski,项目名称:holoviews,代码行数:70,代码来源:testdataset.py


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