Skip to content Skip to sidebar Skip to footer

Selecting Rows - Based On A List - From A Df With Duplicated Columns

I have the following Data frame: import pandas as pd rep = pd.DataFrame.from_items([('Probe', ['x', 'y', 'z']), ('Gene', ['foo', 'bar', 'qux']), ('Probe',['x','y','z']), ('RP',[1.

Solution 1:

You should use iloc here:

In[11]: rep.iloc[rep.iloc[0].isin(ls).values]
Out[11]:
  ProbeGeneProbeRP0xfoox1.02zquxz4.5

This first creates the boolean vector (as a one-dimensional array rather than a DataFrame), and you can use this as a mask:

In [12]: rep.iloc[0].isin(ls).valuesOut[12]: array([ True, False,  True, False], dtype=bool)

Solution 2:

You should probably mention if the list in question ls contains values belonging to a fixed column, say, Probe in this case. If that is the case then the following works.

rep.ix[rep.Probe.isin(ls).ix[:,1]]

Post a Comment for "Selecting Rows - Based On A List - From A Df With Duplicated Columns"