I created a Panel
construct from Pandas
with Python
(see code). After that I generalized (sum) the time with the resample()
function.
import pandas as pd
import numpy as np
time_rng = pd.date_range('1/1/2000', '31/1/2000', freq='D')
PanelData = pd.Panel(np.random.randn(3, 31, 6),
items=['Fish', 'Meat', 'Vegetables'],
major_axis=time_rng,
minor_axis=['a', 'b', 'c', 'd', 'e', 'f'])
Data request:
PanelData
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 31 (major_axis) x 6 (minor_axis)
Items axis: Fish to Vegetables
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-31 00:00:00
Minor_axis axis: a to f
PanelData.resample('W', how='sum', axis=1)
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 6 (major_axis) x 6 (minor_axis)
Items axis: Fish to Vegetables
Major_axis axis: 2000-01-02 00:00:00 to 2000-02-06 00:00:00
Minor_axis axis: a to f
How can I generalize the Minor_axis
with a given list (a=>Zone 1, b=>Zone 1, b=>Zone 2, etc.) that the PanelData will look like:
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 31 (major_axis) x 6 (minor_axis)
Items axis: Fish to Vegetables
Major_axis axis: 2000-01-01 00:00:00 to 2000-01-31 00:00:00
Minor_axis axis: Zone 1 to Zone 3
zones = ['Zone 1', 'Zone 1', 'Zone 2', 'Zone 3', 'Zone 1', 'Zone 2']
NOTE: I'm using Python v.2.7.6
and IPython Notebook v.2.1.0
.