Python Pandas - Logical indexing dataframe with multiple indexes based on single index -
i'm still pretty new pandas i've searched around quite bit , can't quite find i'm looking for.
so here problem:
i have 2 dataframe - 1 mutliple indexes , 1 index
df1= value1 value2 ind1 ind2 1 1.1 7.1 b 2 2.0 8.0 c 3 3.0 9.0 4 4.0 10.0 b 5 5.0 11.0 c 6 6.0 12.0 df2= value1 value2 ind1 8.0 7.0 b 9.0 8.0 c 3.0 9.0 d 11.0 10.0 e 12.0 11.0 f 1.0 12.0
i index data df1 based on df2 value1 > value2.
df2['value1'] > df2['value2']
i know can data df2 with
df2.loc[df2['value1'] > df2['value2']]
but how data df1? tried:
df1.loc[df2['value1'] > df2['value2']]
but fails with
*** indexingerror: unalignable boolean series key provided
any suggestions appreciated, thank you!
get indices df2 , select df1 on indices:
indices = df2.loc[df2['value1'] > df2['value2']] >>>indices index([u'b', u'd', u'e'], dtype='object') >>>df1.ix[indices] ind1 ind2 val1 val2 b 2 2.0 8.0 b 5 5.0 11.0
Comments
Post a Comment