本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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())
示例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')