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


Python Panel.from_dict方法代碼示例

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


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

示例1: test_stack_sparse_frame

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def test_stack_sparse_frame(self, float_frame, float_frame_int_kind,
                                float_frame_fill0, float_frame_fill2):
        def _check(frame):
            dense_frame = frame.to_dense()  # noqa

            wp = Panel.from_dict({'foo': frame})
            from_dense_lp = wp.to_frame()

            from_sparse_lp = spf.stack_sparse_frame(frame)

            tm.assert_numpy_array_equal(from_dense_lp.values,
                                        from_sparse_lp.values)

        _check(float_frame)
        _check(float_frame_int_kind)

        # for now
        pytest.raises(Exception, _check, float_frame_fill0)
        pytest.raises(Exception, _check, float_frame_fill2) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_frame.py

示例2: test_stack_sparse_frame

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

            def _check(frame):
                dense_frame = frame.to_dense()  # noqa

                wp = Panel.from_dict({'foo': frame})
                from_dense_lp = wp.to_frame()

                from_sparse_lp = spf.stack_sparse_frame(frame)

                tm.assert_numpy_array_equal(from_dense_lp.values,
                                            from_sparse_lp.values)

            _check(self.frame)
            _check(self.iframe)

            # for now
            pytest.raises(Exception, _check, self.zframe)
            pytest.raises(Exception, _check, self.fill_frame) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:test_frame.py

示例3: test_stack_sparse_frame

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def test_stack_sparse_frame(self):
        def _check(frame):
            dense_frame = frame.to_dense()

            wp = Panel.from_dict({'foo': frame})
            from_dense_lp = wp.to_frame()

            from_sparse_lp = spf.stack_sparse_frame(frame)

            self.assert_(np.array_equal(from_dense_lp.values,
                                        from_sparse_lp.values))

        _check(self.frame)
        _check(self.iframe)

        # for now
        self.assertRaises(Exception, _check, self.zframe)
        self.assertRaises(Exception, _check, self.fill_frame) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:test_sparse.py

示例4: test_from_dict

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def test_from_dict(self):
        fd = SparsePanel.from_dict(self.data_dict)
        assert_sp_panel_equal(fd, self.panel) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:5,代碼來源:test_sparse.py

示例5: test_dense_to_sparse

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def test_dense_to_sparse(self):
        wp = Panel.from_dict(self.data_dict)
        dwp = wp.to_sparse()
        tm.assert_isinstance(dwp['ItemA']['A'], SparseSeries) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_sparse.py

示例6: test_to_dense

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def test_to_dense(self):
        dwp = self.panel.to_dense()
        dwp2 = Panel.from_dict(self.data_dict)
        assert_panel_equal(dwp, dwp2) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_sparse.py

示例7: testFamaMacBethRolling

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def testFamaMacBethRolling(self):
        # self.checkFamaMacBethExtended('rolling', self.panel_x, self.panel_y,
        #                               nw_lags_beta=2)

        # df = DataFrame(np.random.randn(50, 10))
        x = dict((k, DataFrame(np.random.randn(50, 10))) for k in 'abcdefg')
        x = Panel.from_dict(x)
        y = (DataFrame(np.random.randn(50, 10)) +
             DataFrame(0.01 * np.random.randn(50, 10)))
        self.checkFamaMacBethExtended('rolling', x, y, nw_lags_beta=2)
        self.checkFamaMacBethExtended('expanding', x, y, nw_lags_beta=2) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:test_fama_macbeth.py

示例8: test_merge_nosort

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def test_merge_nosort(self):
        # #2098, anything to do?

        from datetime import datetime

        d = {"var1": np.random.randint(0, 10, size=10),
             "var2": np.random.randint(0, 10, size=10),
             "var3": [datetime(2012, 1, 12), datetime(2011, 2, 4),
                      datetime(
                      2010, 2, 3), datetime(2012, 1, 12),
                      datetime(
                      2011, 2, 4), datetime(2012, 4, 3),
                      datetime(
                      2012, 3, 4), datetime(2008, 5, 1),
                      datetime(2010, 2, 3), datetime(2012, 2, 3)]}
        df = DataFrame.from_dict(d)
        var3 = df.var3.unique()
        var3.sort()
        new = DataFrame.from_dict({"var3": var3,
                                   "var8": np.random.random(7)})

        result = df.merge(new, on="var3", sort=False)
        exp = merge(df, new, on='var3', sort=False)
        assert_frame_equal(result, exp)

        self.assert_((df.var3.unique() == result.var3.unique()).all()) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:28,代碼來源:test_merge.py

示例9: test_panel_join_many

# 需要導入模塊: from pandas import Panel [as 別名]
# 或者: from pandas.Panel import from_dict [as 別名]
def test_panel_join_many(self):
        tm.K = 10
        panel = tm.makePanel()
        tm.K = 4

        panels = [panel.ix[:2], panel.ix[2:6], panel.ix[6:]]

        joined = panels[0].join(panels[1:])
        tm.assert_panel_equal(joined, panel)

        panels = [panel.ix[:2, :-5], panel.ix[2:6, 2:], panel.ix[6:, 5:-7]]

        data_dict = {}
        for p in panels:
            data_dict.update(compat.iteritems(p))

        joined = panels[0].join(panels[1:], how='inner')
        expected = Panel.from_dict(data_dict, intersect=True)
        tm.assert_panel_equal(joined, expected)

        joined = panels[0].join(panels[1:], how='outer')
        expected = Panel.from_dict(data_dict, intersect=False)
        tm.assert_panel_equal(joined, expected)

        # edge cases
        self.assertRaises(ValueError, panels[0].join, panels[1:],
                          how='outer', lsuffix='foo', rsuffix='bar')
        self.assertRaises(ValueError, panels[0].join, panels[1:],
                          how='right') 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:31,代碼來源:test_merge.py


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