AnswerBun.com

pandas isin() fail between dataframes with objects types columns

Stack Overflow Asked by Franco Milanese on January 5, 2022

In [1]: import pandas as pd
   ...: a=pd.DataFrame([1,2,'a'])

In [2]: a.isin([1,'a'])
Out[2]:
       0
0   True
1  False
2   True

In [3]: a.isin(pd.DataFrame([1,'a']))
Out[3]:
       0
0   True
1  False
2  False

why isin cant find ‘a’ in a DataFrame but can in a list?.

PS: Using pandas 1.0.5

In [4]: pd.version
Out[4]: ‘1.0.5’

One Answer

The pd.DataFrame.isin docs spell out this behavior pretty clearly, emphasis my own.

If values is a DataFrame, then both the index and column labels must match.

So looking at your two DataFrames side by side:

a   isin  pd.DataFrame([1,'a'])

   0           0
0  1        0  1    True  <- 1 == 1 for col label (0) and index label (0) 
1  2        1  a    False <- 2 != 'a' for col label (0) and index label (1)
2  a                False <- Nothing to align 

Answered by ALollz on January 5, 2022

Add your own answers!

Related Questions

Keycloak permission to restrict account based resources

0  Asked on December 26, 2020 by james-lin

 

CSS flex, full height sidebar inside a modal?

1  Asked on December 25, 2020 by ddulla

   

Cant loop through List and display in DataTable

1  Asked on December 25, 2020 by finchy70

 

Automate and looping through batch script

2  Asked on December 25, 2020 by nck_505

       

issue connecting Heroku PHP stack to Redis using Predis

0  Asked on December 25, 2020 by rob-edlin

       

Splitting C linked list without making a copy

2  Asked on December 24, 2020

 

Notice Messages Do Not Appear On The Page

1  Asked on December 24, 2020 by cifhai

 

Making comparisons in a HTTPS GET request in node js

0  Asked on December 24, 2020 by thor_

     

SwiftUI Horizontal ScrollView does not scroll

1  Asked on December 23, 2020 by hillinharwich

     

Calling a tab fragment method inside the parent acitivity

0  Asked on December 23, 2020 by aaron-waller

       

Hiding table rows works, but fading out does not

1  Asked on December 23, 2020 by diamondjoe12

       

How to list kubernetes services in k9s?

1  Asked on December 23, 2020 by matthias-m

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP