0

I have to do, maybe a simple thing, but I completely don't know how. I have some code:

data = df_new.assign(result=df_new['text'].isin(df_oryginal['text']).astype(str))
df_same = pd.DataFrame(data)

and the output is:

                                                     text  name          index  result
0                                               some text  filename        0    False
1                                               some text  filename        1    True
2                                               some text  filename        2    False
3                                               some text  filename        3    False
4                                               some text  filename        4    True
...                                                  ...          ...    ...    ...
36213                                           some text  filename    36213    False
36214                                           some text  filename    36214    False
36215                                           some text  filename    36215    True

Now I would like select only these rows where df_same['result'] == True, but I don't know how. I have looked all over Google... Please help me, thank you in advance for your answer :)

Karolina
  • 39
  • 1
  • 2
  • 4
  • 7
    use `df[df['result']]` or ``df.loc[df['result']]`` – Anurag Dabas Aug 06 '21 at 10:08
  • 3
    Did you read the docs? Docs on indexing for both [numpy](https://numpy.org/doc/stable/user/basics.indexing.html), and [pandas](https://pandas.pydata.org/docs/user_guide/indexing.html) are extensive. Maybe you were not familiar with the term indexing? In that case, going through the quick start guide should get you familiarised with most common terminology. – suvayu Aug 06 '21 at 10:15
  • Does this answer your question? [How do I select rows from a DataFrame based on column values?](https://stackoverflow.com/questions/17071871/how-do-i-select-rows-from-a-dataframe-based-on-column-values) – pyeR_biz Aug 06 '21 at 19:05

1 Answers1

8
result_df= df.loc[df['result']==True]

result_df will contain the rows which satisfies your condition having result True

adiiihere
  • 81
  • 1
  • 2
    In case you have a boolean column, you can also just write `result_df= df.loc[df['result']]`. – Moritz Jan 25 '23 at 10:17