How to take subset or matching one row of first dataframe with respect to second dataframe columns in pandas?

python

#1

Hi friends,

I am trying to take subset or matching one row of first dataframe with respect to second dataframe columns
Example:

First Dataframe

s = pd.DataFrame(
     {'User_competencies':['Adapting to change','Coping with change',
       'Managing pressures and` `setbacks','Achieving goals and objectives',
       'Entrepreneurial skills']
     }
)

Second Dataframe

comp[1].head()
0                 Adapting to change
1                 Coping with change
2    Managing pressures and setbacks
3     Achieving goals and objectives
4             Entrepreneurial skills

Now If I want to extract specific row contains using following code:
s["Adapting to change" == comp[1]]

I got Right answer
But I get following warning:

   ` UserWarning: Boolean Series key will be reindexed to match DataFrame index.`
      `"""Entry point for launching an IPython kernel.`

What is this warning means and how can I resolve it?

Because my next step is need to extract more than one row from Dataframe columns.
Can anyone pleas help me?
Thanks in Advance


#2

Hi @premsheth,

The warning comes from the fact that the length of your first Dataframe might not be similar to that of the second Dataframe.

Your method is technically fine, and you’ll get the right answer. But, I would probably do something like this to get rid of the warning:

s[s[“Adapting to change” == comp[1]]]

If this does not resolve the problem, i would suggest you to provide both the Dataframe that would help me to resolve the error in a better way.

Hope this helps!!