-1

i mean i need desired output_dataframe and specific_indexes of Original_dataframe from search_list? How to do that? by fastest way?

Original_dataframe:

   textA  TextB
0       a        zz
1       bbb        zzzzz
2       ccc        zzz

search list:

search_list = ['a','ccc']

i mean i need desired output_dataframe AND specific_indexes of Original_dataframe from search_list

Desired output_dataframe:

   textA  TextB
0       a        zz
2       ccc        zzz

Desired output specific_indexes:

specific_indexes [0, 2]

Computation time is most important.

1 Answers1

2

If need check any column use for index use:

idx = df.index[df.isin(search_list).any(axis=1)]

df1 = df[df.isin(search_list).any(axis=1)]

For check one column by better performance filter indices:

idx = df.index[df['textA'].isin(search_list)]

df1 = df[df['textA'].isin(search_list)]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • 2
    I seriously don't understand your logic on duplicates, IMO this is one (just a very basic check here and not necessarily worthy of answering in full)… NB. I didn't DV – mozway Sep 13 '21 at 07:58
  • @mozway - yop, still not understand? Dupe -> wiki. – jezrael Sep 13 '21 at 08:01
  • Because I considered it **not** a duplicate in good faith, there is no absolute *right* or *wrong*, we are human beings (well, I am) and can have different opinions – mozway Sep 13 '21 at 08:03
  • @mozway - ya, I answer it too in good faith. But after realise it is dupe, no rep hunting, but wiki. So no points... – jezrael Sep 13 '21 at 08:04
  • 1
    I don't blame you for that, but please be aware that your behavior is quite stressful, you really jump at people within minutes, nothing is perfect – mozway Sep 13 '21 at 08:07
  • @jezrael guys i also need to know output_dataframe – Bold Ganbaatar Sep 13 '21 at 08:08
  • @mozway - I have absolutely no problem with answer, but if it is dupe, why rep hunting? Tis is what I dont like. – jezrael Sep 13 '21 at 08:08
  • 1
    @BoldGanbaatar - added to answer. – jezrael Sep 13 '21 at 08:10