Skip to content

Instantly share code, notes, and snippets.

@fnoble
Created February 7, 2014 00:15
Show Gist options
  • Save fnoble/8855189 to your computer and use it in GitHub Desktop.
Save fnoble/8855189 to your computer and use it in GitHub Desktop.
Pandas Panel problem
import pandas
wp = pandas.Panel(randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=pandas.date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
wp2 = pandas.Panel(randn(3, 5, 4), items=['Item1', 'Item2', 'Item3'],
major_axis=pandas.date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
wp.sub(wp2).ix[:, :, 'A']
# Output:
# Item1 Item2 Item3
# 2000-01-01 1.182223 0.385267 -0.370692
# 2000-01-02 -0.358195 -0.040343 0.350876
# 2000-01-03 -0.237364 0.213128 0.313635
# 2000-01-04 -1.093256 0.620667 1.686411
# 2000-01-05 -1.906565 -1.295648 -0.644578
#
# Why is column 'Item3' there?
@fnoble
Copy link
Author

fnoble commented Feb 7, 2014

This actually seems to be particular to the items axis, the following seems to work:

(wp.transpose(1,0,2)).sub(wp2.transpose(1,0,2)).ix[:, :, 'A'].T

               Item1     Item2  Item3
2000-01-01  0.398772 -0.036486    NaN
2000-01-02 -0.386096  1.152324    NaN
2000-01-03 -2.046829  0.582434    NaN
2000-01-04  0.137687 -0.661586    NaN
2000-01-05  0.480794 -0.362363    NaN

@fnoble
Copy link
Author

fnoble commented Feb 7, 2014

Pandas version is 0.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment