python 2.7 - parallel indexing in pandas dataframe using a pandas series? -


if have data frame looks this:

      a      b      c      d
0    10 15     23    56
1    11    64    66    34
2    46    98    56    87
3    3     49     89    100
4    57    32    48    27
5    99    68    35    19
6    65    79    95    91
8    79    44    66    92

the indicies interested in each column follows (the indicdes in form of series):
      a    b    c    d
0    3    5    8    1

so result want is
      a    b      c      d
0    3    68    66    34

i want able pull out result

i can convert indicies array if need goal index these different columns in parallel.

you use dataframe.lookup, , build new frame. not prettiest, but:

>>> s    3 b    5 c    8 d    1 name: 0, dtype: int64 >>> df.lookup(s.values, s.keys()) array([ 3, 68, 66, 34]) >>> pd.dataframe(dict(zip(s.keys(), df.lookup(s.values, s.keys()))), index=[0])      b   c   d 0  3  68  66  34 

where i'm assuming we're using s, series, hold indices.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -