Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pandas Panel doesn't support getting DataFrame or (sub) Panel using a list of index #8710

Closed
femtotrader opened this issue Nov 2, 2014 · 3 comments · Fixed by #8715
Closed
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@femtotrader
Copy link

Hello,

when I try to get a DataFrame (or sub Panel) from a Panel using index as list it raises the following error:

TypeError: unhashable type: 'list'

See the code

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pandas as pd
import pandas.io.data as web

start = "2010-01-01"
end = "2010-01-30"

df = web.DataReader("AAPL", 'yahoo', start, end)

print("DF 1")
data = df[['Open', 'Close']] # returns pandas.core.frame.DataFrame
print(data)
print(type(data))

print("DF 2")
data = df['Open'] # returns pandas.core.series.Series
print(data)
print(type(data))

print("DF 3")
data = df[['Open']] # returns pandas.core.frame.DataFrame
print(data)
print(type(data))

panel = web.DataReader(["AAPL", "GOOGL"], 'yahoo', start, end)
#Items axis: Open to Adj Close
#Major_axis axis: 2010-01-04 00:00:00 to 2010-01-29 00:00:00
#Minor_axis axis: AAPL to GOOGL
panel = panel.transpose(2, 1, 0) # symbol is panel index
#Items axis: AAPL to GOOGL
#Major_axis axis: 2010-01-04 00:00:00 to 2010-01-29 00:00:00
#Minor_axis axis: Open to Adj Close
print(panel)

print("P 1")
data = panel["AAPL"] # returns pandas.core.frame.DataFrame
print(data)
print(type(data))

print("P 2")
#data = panel[["AAPL"]] # Error: Should return a DataFrame but raises TypeError: unhashable type: 'list'
#print(data)    
#print(type(data))

print("P 3")
#data = panel[["AAPL", "GOOGL"]] # Error: Should return a "sub" Panel but raises TypeError: unhashable type: 'list'

#print(data)
#print(type(data))

But that can be a misunderstanding on my side.

Thanks

@jreback
Copy link
Contributor

jreback commented Nov 2, 2014

pd.show_versions() pls

@femtotrader
Copy link
Author

pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Darwin
OS-release: 11.4.2
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8

pandas: 0.15.0
nose: 1.3.4
Cython: 0.21
numpy: 1.8.1
scipy: 0.14.0
statsmodels: 0.5.0
IPython: 2.2.0
sphinx: 1.2.3
patsy: 0.3.0
dateutil: 2.2
pytz: 2014.7
bottleneck: None
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.4.0
openpyxl: 2.0.3
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: 0.5.7
lxml: 3.3.6
bs4: 4.3.2
html5lib: 0.999
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: 0.9.7
pymysql: None
psycopg2: None  

@jreback
Copy link
Contributor

jreback commented Nov 2, 2014

hmm, it does look buggy

this is the general access method (note that this is with 0.15.1/master). A couple of indexing bugs were fixed in in 0.15.0 so worthile to upgrade.

In [18]: panel.loc[:,:,['AAPL','GOOGL']]
Out[18]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 6 (items) x 19 (major_axis) x 2 (minor_axis)
Items axis: Open to Adj Close
Major_axis axis: 2010-01-04 00:00:00 to 2010-01-29 00:00:00
Minor_axis axis: AAPL to GOOGL

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 2, 2014
@jreback jreback added this to the 0.15.1 milestone Nov 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants