python - Pulling multiple, non-consecutive index values from a Pandas DataFrame -


i've created pandas dataframe reading scipy.io in following way (file.sav idl structure created on different machine. scipy.io creates standard python dictionary):

from scipy import io import pandas p import numpy np tmp=io.readsav('file.sav', python_dict = true) df=pd.dataframe(tmp,index=tmp['shots'].astype('int32')) 

the dataframe contains set of values (from file.sav) , indices series of integers of form 19999,20000,30000 etc. take subset of these indices, says

df.loc[[19999,20000]] 

for reasons errors of form

raise valueerror('cannot index multidimensional key') 

plus other , @ end

valueerror: big-endian buffer not supported on little-endian compiler 

but i've checked both machine i'm working on , machine has created file.sav both little endian. don't think problem.

your input file big endian. see here transform it: http://pandas.pydata.org/pandas-docs/dev/gotchas.html#byte-ordering-issues

compare before , after

in [7]: df.dtypes out[7]:         >f4 b        >f4 c        >f4 shots    >f4 dtype: object  in [9]: df.apply(lambda x: x.values.byteswap().newbyteorder()) out[9]:  <class 'pandas.core.frame.dataframe'> int64index: 100 entries, 20000 20099 data columns (total 4 columns):        100  non-null values b        100  non-null values c        100  non-null values shots    100  non-null values dtypes: float32(4)  in [10]: df.apply(lambda x: x.values.byteswap().newbyteorder()).dtypes out[10]:         float32 b        float32 c        float32 shots    float32 dtype: object 

also set index after (e.g. don't in constructor)

df.set_index('shots',inplace=true) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -