本文整理汇总了Python中pandas.Panel方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.Panel方法的具体用法?Python pandas.Panel怎么用?Python pandas.Panel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas
的用法示例。
在下文中一共展示了pandas.Panel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_data
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def load_data(file_path):
d = binarywave.load(file_path)
dat = d["wave"]["wData"]
if dat.shape[-1] not in [4, 6]:
print ("invalid file")
return
labels = (
[
"Height",
"Amplitude 1",
"Amplitude 2",
"Phase 1",
"Phase 2",
"Resonance Frequency",
]
if dat.shape[-1] == 6
else ["Height", "Amplitude", "Phase", "z sensor"]
)
return Panel(dat, minor_axis=labels).transpose(2, 0, 1).to_frame()
示例2: load_RSM
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def load_RSM(filename):
om, tt, psd = xu.io.getxrdml_map(filename)
om = np.deg2rad(om)
tt = np.deg2rad(tt)
wavelength = 1.54056
q_y = (1 / wavelength) * (np.cos(tt) - np.cos(2 * om - tt))
q_x = (1 / wavelength) * (np.sin(tt) - np.sin(2 * om - tt))
xi = np.linspace(np.min(q_x), np.max(q_x), 100)
yi = np.linspace(np.min(q_y), np.max(q_y), 100)
psd[psd < 1] = 1
data_grid = griddata(
(q_x, q_y), psd, (xi[None, :], yi[:, None]), fill_value=1, method="cubic"
)
nx, ny = data_grid.shape
range_values = [np.min(q_x), np.max(q_x), np.min(q_y), np.max(q_y)]
output_data = (
Panel(np.log(data_grid).reshape(nx, ny, 1), minor_axis=["RSM"])
.transpose(2, 0, 1)
.to_frame()
)
return range_values, output_data
示例3: test_panel_concat_buglet
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_panel_concat_buglet(self, sort):
# #2257
def make_panel():
index = 5
cols = 3
def df():
return DataFrame(np.random.randn(index, cols),
index=["I%s" % i for i in range(index)],
columns=["C%s" % i for i in range(cols)])
return Panel({"Item%s" % x: df() for x in ['A', 'B', 'C']})
panel1 = make_panel()
panel2 = make_panel()
panel2 = panel2.rename(major_axis={x: "%s_1" % x
for x in panel2.major_axis})
panel3 = panel2.rename(major_axis=lambda x: '%s_1' % x)
panel3 = panel3.rename(minor_axis=lambda x: '%s_1' % x)
# it works!
concat([panel1, panel3], axis=1, verify_integrity=True, sort=sort)
示例4: test_panel_assignment
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_panel_assignment(self):
with catch_warnings(record=True):
# GH3777
wp = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
wp2 = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
# TODO: unused?
# expected = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
with pytest.raises(NotImplementedError):
wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = wp2.loc[
['Item1', 'Item2'], :, ['A', 'B']]
# to_assign = wp2.loc[['Item1', 'Item2'], :, ['A', 'B']]
# wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = to_assign
# result = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
# tm.assert_panel_equal(result,expected)
示例5: test_to_panel_expanddim
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_to_panel_expanddim(self):
# GH 9762
class SubclassedFrame(DataFrame):
@property
def _constructor_expanddim(self):
return SubclassedPanel
class SubclassedPanel(Panel):
pass
index = MultiIndex.from_tuples([(0, 0), (0, 1), (0, 2)])
df = SubclassedFrame({'X': [1, 2, 3], 'Y': [4, 5, 6]}, index=index)
result = df.to_panel()
assert isinstance(result, SubclassedPanel)
expected = SubclassedPanel([[[1, 2, 3]], [[4, 5, 6]]],
items=['X', 'Y'], major_axis=[0],
minor_axis=[0, 1, 2],
dtype='int64')
tm.assert_panel_equal(result, expected)
示例6: test_panel_aggregation
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_panel_aggregation():
ind = pd.date_range('1/1/2000', periods=100)
data = np.random.randn(2, len(ind), 4)
wp = Panel(data, items=['Item1', 'Item2'], major_axis=ind,
minor_axis=['A', 'B', 'C', 'D'])
tg = TimeGrouper('M', axis=1)
_, grouper, _ = tg._get_grouper(wp)
bingrouped = wp.groupby(grouper)
binagg = bingrouped.mean()
def f(x):
assert (isinstance(x, Panel))
return x.mean(1)
result = bingrouped.agg(f)
tm.assert_panel_equal(result, binagg)
示例7: test_resample_panel_numpy
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_resample_panel_numpy():
rng = date_range('1/1/2000', '6/30/2000')
n = len(rng)
with catch_warnings(record=True):
panel = Panel(np.random.randn(3, n, 5),
items=['one', 'two', 'three'],
major_axis=rng,
minor_axis=['a', 'b', 'c', 'd', 'e'])
result = panel.resample('M', axis=1).apply(lambda x: x.mean(1))
expected = panel.resample('M', axis=1).mean()
tm.assert_panel_equal(result, expected)
panel = panel.swapaxes(1, 2)
result = panel.resample('M', axis=2).apply(lambda x: x.mean(2))
expected = panel.resample('M', axis=2).mean()
tm.assert_panel_equal(result, expected)
示例8: test_binary_ops_docs
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_binary_ops_docs(self):
from pandas import DataFrame, Panel
op_map = {'add': '+',
'sub': '-',
'mul': '*',
'mod': '%',
'pow': '**',
'truediv': '/',
'floordiv': '//'}
for op_name in ['add', 'sub', 'mul', 'mod', 'pow', 'truediv',
'floordiv']:
for klass in [Series, DataFrame, Panel]:
operand1 = klass.__name__.lower()
operand2 = 'other'
op = op_map[op_name]
expected_str = ' '.join([operand1, op, operand2])
assert expected_str in getattr(klass, op_name).__doc__
# reverse version of the binary ops
expected_str = ' '.join([operand2, op, operand1])
assert expected_str in getattr(klass, 'r' + op_name).__doc__
示例9: test_drop_labels_or_levels_series
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_drop_labels_or_levels_series(df):
# Make series with L1 as index
s = df.set_index('L1').L2
assert_levels_dropped(s, ['L1'], axis=0)
with tm.assert_raises_regex(ValueError, "not valid labels or levels"):
s._drop_labels_or_levels('L4', axis=0)
# Make series with L1 and L2 as index
s = df.set_index(['L1', 'L2']).L3
assert_levels_dropped(s, ['L1', 'L2'], axis=0)
with tm.assert_raises_regex(ValueError, "not valid labels or levels"):
s._drop_labels_or_levels('L4', axis=0)
# Panel
# -----
示例10: test_panel_assignment
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_panel_assignment(self):
with catch_warnings(record=True):
# GH3777
wp = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
wp2 = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
# TODO: unused?
# expected = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
def f():
wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = wp2.loc[
['Item1', 'Item2'], :, ['A', 'B']]
pytest.raises(NotImplementedError, f)
# to_assign = wp2.loc[['Item1', 'Item2'], :, ['A', 'B']]
# wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = to_assign
# result = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
# tm.assert_panel_equal(result,expected)
示例11: test_to_panel_expanddim
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_to_panel_expanddim(self):
# GH 9762
with catch_warnings(record=True):
class SubclassedFrame(DataFrame):
@property
def _constructor_expanddim(self):
return SubclassedPanel
class SubclassedPanel(Panel):
pass
index = MultiIndex.from_tuples([(0, 0), (0, 1), (0, 2)])
df = SubclassedFrame({'X': [1, 2, 3], 'Y': [4, 5, 6]}, index=index)
result = df.to_panel()
assert isinstance(result, SubclassedPanel)
expected = SubclassedPanel([[[1, 2, 3]], [[4, 5, 6]]],
items=['X', 'Y'], major_axis=[0],
minor_axis=[0, 1, 2],
dtype='int64')
tm.assert_panel_equal(result, expected)
示例12: test_resample_panel
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_resample_panel(self):
rng = date_range('1/1/2000', '6/30/2000')
n = len(rng)
panel = Panel(np.random.randn(3, n, 5),
items=['one', 'two', 'three'],
major_axis=rng,
minor_axis=['a', 'b', 'c', 'd', 'e'])
result = panel.resample('M', axis=1)
def p_apply(panel, f):
result = {}
for item in panel.items:
result[item] = f(panel[item])
return Panel(result, items=panel.items)
expected = p_apply(panel, lambda x: x.resample('M'))
tm.assert_panel_equal(result, expected)
panel2 = panel.swapaxes(1, 2)
result = panel2.resample('M', axis=2)
expected = p_apply(panel2, lambda x: x.resample('M', axis=1))
tm.assert_panel_equal(result, expected)
示例13: test_resample_panel_numpy
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_resample_panel_numpy(self):
rng = date_range('1/1/2000', '6/30/2000')
n = len(rng)
panel = Panel(np.random.randn(3, n, 5),
items=['one', 'two', 'three'],
major_axis=rng,
minor_axis=['a', 'b', 'c', 'd', 'e'])
result = panel.resample('M', how=lambda x: x.mean(1), axis=1)
expected = panel.resample('M', how='mean', axis=1)
tm.assert_panel_equal(result, expected)
panel = panel.swapaxes(1, 2)
result = panel.resample('M', how=lambda x: x.mean(2), axis=2)
expected = panel.resample('M', how='mean', axis=2)
tm.assert_panel_equal(result, expected)
示例14: test_panel_aggregation
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def test_panel_aggregation(self):
ind = pd.date_range('1/1/2000', periods=100)
data = np.random.randn(2, len(ind), 4)
wp = pd.Panel(data, items=['Item1', 'Item2'], major_axis=ind,
minor_axis=['A', 'B', 'C', 'D'])
tg = TimeGrouper('M', axis=1)
grouper = tg.get_grouper(wp)
bingrouped = wp.groupby(grouper)
binagg = bingrouped.mean()
def f(x):
assert(isinstance(x, Panel))
return x.mean(1)
result = bingrouped.agg(f)
tm.assert_panel_equal(result, binagg)
示例15: _dl_mult_symbols
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Panel [as 别名]
def _dl_mult_symbols(symbols, start, end, chunksize, retry_count, pause,
method):
stocks = {}
for sym_group in _in_chunks(symbols, chunksize):
for sym in sym_group:
try:
stocks[sym] = method(sym, start, end, retry_count, pause)
except IOError:
warnings.warn('Failed to read symbol: {0!r}, replacing with '
'NaN.'.format(sym), SymbolWarning)
stocks[sym] = np.nan
try:
return Panel(stocks).swapaxes('items', 'minor')
except AttributeError:
# cannot construct a panel with just 1D nans indicating no data
raise RemoteDataError("No data fetched using "
"{0!r}".format(method.__name__))