當前位置: 首頁>>代碼示例>>Python>>正文


Python Panel.from_dict方法代碼示例

本文整理匯總了Python中pandas.core.panel.Panel.from_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python Panel.from_dict方法的具體用法?Python Panel.from_dict怎麽用?Python Panel.from_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.core.panel.Panel的用法示例。


在下文中一共展示了Panel.from_dict方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ctor_orderedDict

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_ctor_orderedDict(self):
        keys = list(set(np.random.randint(0, 5000, 100)))[
            :50]  # unique random int  keys
        d = OrderedDict([(k, mkdf(10, 5)) for k in keys])
        p = Panel(d)
        assert list(p.items) == keys

        p = Panel.from_dict(d)
        assert list(p.items) == keys 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_panel.py

示例2: test_from_dict_mixed_orient

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_from_dict_mixed_orient(self):
        df = tm.makeDataFrame()
        df['foo'] = 'bar'

        data = {'k1': df, 'k2': df}

        panel = Panel.from_dict(data, orient='minor')

        assert panel['foo'].values.dtype == np.object_
        assert panel['A'].values.dtype == np.float64 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_panel.py

示例3: test_shift

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_shift(self):
        # major
        idx = self.panel.major_axis[0]
        idx_lag = self.panel.major_axis[1]
        shifted = self.panel.shift(1)
        assert_frame_equal(self.panel.major_xs(idx),
                           shifted.major_xs(idx_lag))

        # minor
        idx = self.panel.minor_axis[0]
        idx_lag = self.panel.minor_axis[1]
        shifted = self.panel.shift(1, axis='minor')
        assert_frame_equal(self.panel.minor_xs(idx),
                           shifted.minor_xs(idx_lag))

        # items
        idx = self.panel.items[0]
        idx_lag = self.panel.items[1]
        shifted = self.panel.shift(1, axis='items')
        assert_frame_equal(self.panel[idx], shifted[idx_lag])

        # negative numbers, #2164
        result = self.panel.shift(-1)
        expected = Panel({i: f.shift(-1)[:-1]
                          for i, f in self.panel.iteritems()})
        assert_panel_equal(result, expected)

        # mixed dtypes #6959
        data = [('item ' + ch, makeMixedDataFrame())
                for ch in list('abcde')]
        data = dict(data)
        mixed_panel = Panel.from_dict(data, orient='minor')
        shifted = mixed_panel.shift(1)
        assert_series_equal(mixed_panel.dtypes, shifted.dtypes) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:36,代碼來源:test_panel.py

示例4: test_ctor_orderedDict

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_ctor_orderedDict(self):
        with catch_warnings(record=True):
            keys = list(set(np.random.randint(0, 5000, 100)))[
                :50]  # unique random int  keys
            d = OrderedDict([(k, mkdf(10, 5)) for k in keys])
            p = Panel(d)
            assert list(p.items) == keys

            p = Panel.from_dict(d)
            assert list(p.items) == keys 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:12,代碼來源:test_panel.py

示例5: test_from_dict_mixed_orient

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_from_dict_mixed_orient(self):
        with catch_warnings(record=True):
            df = tm.makeDataFrame()
            df['foo'] = 'bar'

            data = {'k1': df, 'k2': df}

            panel = Panel.from_dict(data, orient='minor')

            assert panel['foo'].values.dtype == np.object_
            assert panel['A'].values.dtype == np.float64 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:13,代碼來源:test_panel.py

示例6: test_shift

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_shift(self):
        with catch_warnings(record=True):
            # major
            idx = self.panel.major_axis[0]
            idx_lag = self.panel.major_axis[1]
            shifted = self.panel.shift(1)
            assert_frame_equal(self.panel.major_xs(idx),
                               shifted.major_xs(idx_lag))

            # minor
            idx = self.panel.minor_axis[0]
            idx_lag = self.panel.minor_axis[1]
            shifted = self.panel.shift(1, axis='minor')
            assert_frame_equal(self.panel.minor_xs(idx),
                               shifted.minor_xs(idx_lag))

            # items
            idx = self.panel.items[0]
            idx_lag = self.panel.items[1]
            shifted = self.panel.shift(1, axis='items')
            assert_frame_equal(self.panel[idx], shifted[idx_lag])

            # negative numbers, #2164
            result = self.panel.shift(-1)
            expected = Panel({i: f.shift(-1)[:-1]
                              for i, f in self.panel.iteritems()})
            assert_panel_equal(result, expected)

            # mixed dtypes #6959
            data = [('item ' + ch, makeMixedDataFrame())
                    for ch in list('abcde')]
            data = dict(data)
            mixed_panel = Panel.from_dict(data, orient='minor')
            shifted = mixed_panel.shift(1)
            assert_series_equal(mixed_panel.dtypes, shifted.dtypes) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:37,代碼來源:test_panel.py

示例7: from_dict

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def from_dict(cls, data):
        """
        Analogous to Panel.from_dict
        """
        return SparsePanel(data) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:panel.py

示例8: var_beta

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def var_beta(self):
        """Returns the covariance of beta."""
        result = {}
        result_index = self._result_index
        for i in range(len(self._var_beta_raw)):
            dm = DataFrame(self._var_beta_raw[i], columns=self.beta.columns,
                           index=self.beta.columns)
            result[result_index[i]] = dm

        return Panel.from_dict(result, intersect=False) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:ols.py

示例9: test_shift

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_shift(self):
        with catch_warnings(record=True):
            # major
            idx = self.panel.major_axis[0]
            idx_lag = self.panel.major_axis[1]
            shifted = self.panel.shift(1)
            assert_frame_equal(self.panel.major_xs(idx),
                               shifted.major_xs(idx_lag))

            # minor
            idx = self.panel.minor_axis[0]
            idx_lag = self.panel.minor_axis[1]
            shifted = self.panel.shift(1, axis='minor')
            assert_frame_equal(self.panel.minor_xs(idx),
                               shifted.minor_xs(idx_lag))

            # items
            idx = self.panel.items[0]
            idx_lag = self.panel.items[1]
            shifted = self.panel.shift(1, axis='items')
            assert_frame_equal(self.panel[idx], shifted[idx_lag])

            # negative numbers, #2164
            result = self.panel.shift(-1)
            expected = Panel(dict((i, f.shift(-1)[:-1])
                                  for i, f in self.panel.iteritems()))
            assert_panel_equal(result, expected)

            # mixed dtypes #6959
            data = [('item ' + ch, makeMixedDataFrame())
                    for ch in list('abcde')]
            data = dict(data)
            mixed_panel = Panel.from_dict(data, orient='minor')
            shifted = mixed_panel.shift(1)
            assert_series_equal(mixed_panel.dtypes, shifted.dtypes) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:37,代碼來源:test_panel.py

示例10: test_constructor_dtypes

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_constructor_dtypes(self):
        # GH #797

        def _check_dtype(panel, dtype):
            for i in panel.items:
                assert panel[i].values.dtype.name == dtype

        # only nan holding types allowed here
        for dtype in ['float64', 'float32', 'object']:
            panel = Panel(items=lrange(2), major_axis=lrange(10),
                          minor_axis=lrange(5), dtype=dtype)
            _check_dtype(panel, dtype)

        for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
            panel = Panel(np.array(np.random.randn(2, 10, 5), dtype=dtype),
                          items=lrange(2),
                          major_axis=lrange(10),
                          minor_axis=lrange(5), dtype=dtype)
            _check_dtype(panel, dtype)

        for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
            panel = Panel(np.array(np.random.randn(2, 10, 5), dtype='O'),
                          items=lrange(2),
                          major_axis=lrange(10),
                          minor_axis=lrange(5), dtype=dtype)
            _check_dtype(panel, dtype)

        for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
            panel = Panel(
                np.random.randn(2, 10, 5),
                items=lrange(2), major_axis=lrange(10),
                minor_axis=lrange(5),
                dtype=dtype)
            _check_dtype(panel, dtype)

        for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
            df1 = DataFrame(np.random.randn(2, 5),
                            index=lrange(2), columns=lrange(5))
            df2 = DataFrame(np.random.randn(2, 5),
                            index=lrange(2), columns=lrange(5))
            panel = Panel.from_dict({'a': df1, 'b': df2}, dtype=dtype)
            _check_dtype(panel, dtype) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:44,代碼來源:test_panel.py

示例11: test_ctor_dict

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_ctor_dict(self):
        itema = self.panel['ItemA']
        itemb = self.panel['ItemB']

        d = {'A': itema, 'B': itemb[5:]}
        d2 = {'A': itema._series, 'B': itemb[5:]._series}
        d3 = {'A': None,
              'B': DataFrame(itemb[5:]._series),
              'C': DataFrame(itema._series)}

        wp = Panel.from_dict(d)
        wp2 = Panel.from_dict(d2)  # nested Dict

        # TODO: unused?
        wp3 = Panel.from_dict(d3)  # noqa

        tm.assert_index_equal(wp.major_axis, self.panel.major_axis)
        assert_panel_equal(wp, wp2)

        # intersect
        wp = Panel.from_dict(d, intersect=True)
        tm.assert_index_equal(wp.major_axis, itemb.index[5:])

        # use constructor
        assert_panel_equal(Panel(d), Panel.from_dict(d))
        assert_panel_equal(Panel(d2), Panel.from_dict(d2))
        assert_panel_equal(Panel(d3), Panel.from_dict(d3))

        # a pathological case
        d4 = {'A': None, 'B': None}

        # TODO: unused?
        wp4 = Panel.from_dict(d4)  # noqa

        assert_panel_equal(Panel(d4), Panel(items=['A', 'B']))

        # cast
        dcasted = {k: v.reindex(wp.major_axis).fillna(0)
                   for k, v in compat.iteritems(d)}
        result = Panel(dcasted, dtype=int)
        expected = Panel({k: v.astype(int)
                          for k, v in compat.iteritems(dcasted)})
        assert_panel_equal(result, expected)

        result = Panel(dcasted, dtype=np.int32)
        expected = Panel({k: v.astype(np.int32)
                          for k, v in compat.iteritems(dcasted)})
        assert_panel_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:50,代碼來源:test_panel.py

示例12: test_constructor_dtypes

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_constructor_dtypes(self):
        with catch_warnings(record=True):
            # GH #797

            def _check_dtype(panel, dtype):
                for i in panel.items:
                    assert panel[i].values.dtype.name == dtype

            # only nan holding types allowed here
            for dtype in ['float64', 'float32', 'object']:
                panel = Panel(items=lrange(2), major_axis=lrange(10),
                              minor_axis=lrange(5), dtype=dtype)
                _check_dtype(panel, dtype)

            for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
                panel = Panel(np.array(np.random.randn(2, 10, 5), dtype=dtype),
                              items=lrange(2),
                              major_axis=lrange(10),
                              minor_axis=lrange(5), dtype=dtype)
                _check_dtype(panel, dtype)

            for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
                panel = Panel(np.array(np.random.randn(2, 10, 5), dtype='O'),
                              items=lrange(2),
                              major_axis=lrange(10),
                              minor_axis=lrange(5), dtype=dtype)
                _check_dtype(panel, dtype)

            for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
                panel = Panel(
                    np.random.randn(2, 10, 5),
                    items=lrange(2), major_axis=lrange(10),
                    minor_axis=lrange(5),
                    dtype=dtype)
                _check_dtype(panel, dtype)

            for dtype in ['float64', 'float32', 'int64', 'int32', 'object']:
                df1 = DataFrame(np.random.randn(2, 5),
                                index=lrange(2), columns=lrange(5))
                df2 = DataFrame(np.random.randn(2, 5),
                                index=lrange(2), columns=lrange(5))
                panel = Panel.from_dict({'a': df1, 'b': df2}, dtype=dtype)
                _check_dtype(panel, dtype) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:45,代碼來源:test_panel.py

示例13: test_ctor_dict

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_ctor_dict(self):
        with catch_warnings(record=True):
            itema = self.panel['ItemA']
            itemb = self.panel['ItemB']

            d = {'A': itema, 'B': itemb[5:]}
            d2 = {'A': itema._series, 'B': itemb[5:]._series}
            d3 = {'A': None,
                  'B': DataFrame(itemb[5:]._series),
                  'C': DataFrame(itema._series)}

            wp = Panel.from_dict(d)
            wp2 = Panel.from_dict(d2)  # nested Dict

            # TODO: unused?
            wp3 = Panel.from_dict(d3)  # noqa

            tm.assert_index_equal(wp.major_axis, self.panel.major_axis)
            assert_panel_equal(wp, wp2)

            # intersect
            wp = Panel.from_dict(d, intersect=True)
            tm.assert_index_equal(wp.major_axis, itemb.index[5:])

            # use constructor
            assert_panel_equal(Panel(d), Panel.from_dict(d))
            assert_panel_equal(Panel(d2), Panel.from_dict(d2))
            assert_panel_equal(Panel(d3), Panel.from_dict(d3))

            # a pathological case
            d4 = {'A': None, 'B': None}

            # TODO: unused?
            wp4 = Panel.from_dict(d4)  # noqa

            assert_panel_equal(Panel(d4), Panel(items=['A', 'B']))

            # cast
            dcasted = {k: v.reindex(wp.major_axis).fillna(0)
                       for k, v in compat.iteritems(d)}
            result = Panel(dcasted, dtype=int)
            expected = Panel({k: v.astype(int)
                              for k, v in compat.iteritems(dcasted)})
            assert_panel_equal(result, expected)

            result = Panel(dcasted, dtype=np.int32)
            expected = Panel({k: v.astype(np.int32)
                              for k, v in compat.iteritems(dcasted)})
            assert_panel_equal(result, expected) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:51,代碼來源:test_panel.py

示例14: _filter_data

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def _filter_data(self):
        """

        """
        data = self._x_orig
        cat_mapping = {}

        if isinstance(data, DataFrame):
            data = data.to_panel()
        else:
            if isinstance(data, Panel):
                data = data.copy()

            if not isinstance(data, SparsePanel):
                data, cat_mapping = self._convert_x(data)

            if not isinstance(data, Panel):
                data = Panel.from_dict(data, intersect=True)

        x_names = data.items

        if self._weights is not None:
            data['__weights__'] = self._weights

        # Filter x's without y (so we can make a prediction)
        filtered = data.to_frame()

        # Filter all data together using to_frame

        # convert to DataFrame
        y = self._y_orig
        if isinstance(y, Series):
            y = y.unstack()

        data['__y__'] = y
        data_long = data.to_frame()

        x_filt = filtered.filter(x_names)
        x = data_long.filter(x_names)
        y = data_long['__y__']

        if self._weights is not None and not self._weights.empty:
            weights = data_long['__weights__']
        else:
            weights = None

        return x, x_filt, y, weights, cat_mapping 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:49,代碼來源:plm.py

示例15: test_ctor_dict

# 需要導入模塊: from pandas.core.panel import Panel [as 別名]
# 或者: from pandas.core.panel.Panel import from_dict [as 別名]
def test_ctor_dict(self):
        with catch_warnings(record=True):
            itema = self.panel['ItemA']
            itemb = self.panel['ItemB']

            d = {'A': itema, 'B': itemb[5:]}
            d2 = {'A': itema._series, 'B': itemb[5:]._series}
            d3 = {'A': None,
                  'B': DataFrame(itemb[5:]._series),
                  'C': DataFrame(itema._series)}

            wp = Panel.from_dict(d)
            wp2 = Panel.from_dict(d2)  # nested Dict

            # TODO: unused?
            wp3 = Panel.from_dict(d3)  # noqa

            tm.assert_index_equal(wp.major_axis, self.panel.major_axis)
            assert_panel_equal(wp, wp2)

            # intersect
            wp = Panel.from_dict(d, intersect=True)
            tm.assert_index_equal(wp.major_axis, itemb.index[5:])

            # use constructor
            assert_panel_equal(Panel(d), Panel.from_dict(d))
            assert_panel_equal(Panel(d2), Panel.from_dict(d2))
            assert_panel_equal(Panel(d3), Panel.from_dict(d3))

            # a pathological case
            d4 = {'A': None, 'B': None}

            # TODO: unused?
            wp4 = Panel.from_dict(d4)  # noqa

            assert_panel_equal(Panel(d4), Panel(items=['A', 'B']))

            # cast
            dcasted = dict((k, v.reindex(wp.major_axis).fillna(0))
                           for k, v in compat.iteritems(d))
            result = Panel(dcasted, dtype=int)
            expected = Panel(dict((k, v.astype(int))
                                  for k, v in compat.iteritems(dcasted)))
            assert_panel_equal(result, expected)

            result = Panel(dcasted, dtype=np.int32)
            expected = Panel(dict((k, v.astype(np.int32))
                                  for k, v in compat.iteritems(dcasted)))
            assert_panel_equal(result, expected) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:51,代碼來源:test_panel.py


注:本文中的pandas.core.panel.Panel.from_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。