0

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.

joris
  • 133,120
  • 36
  • 247
  • 202
Spirou
  • 257
  • 4
  • 10
  • Do you just want to rename the labels in Minor_axis (a -> Zone 1, b -> Zone 1, c -> Zone 2, etc)? What has this to do with the resample? – joris Aug 26 '14 at 13:16

1 Answers1

1

Sorry about my interrogation. It's more an issue for the groupby() function. I found the solution I asked for.

zones = ['Zone 1', 'Zone 1', 'Zone 2', 'Zone 3', 'Zone 1', 'Zone 2']

PanelData.groupby(zones, axis=2).sum()
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 31 (major_axis) x 3 (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
Spirou
  • 257
  • 4
  • 10