Python Pandas Only Compare Identically Labeled DataFrame Objects

后端 未结 3 957
独厮守ぢ
独厮守ぢ 2021-01-12 15:13

I tried all the solutions here: Pandas "Can only compare identically-labeled DataFrame objects" error

Didn\'t work for me. Here\'s what I\'ve got. I hav

3条回答
  •  走了就别回头了
    2021-01-12 15:55

    In order to get around this, you want to compare the underlying numpy arrays.

    import pandas as pd
    
    df1 = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'], index=['One', 'Two'])
    df2 = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b'], index=['one', 'two'])
    
    
    df1.values == df2.values
    
    array([[ True,  True],
           [ True,  True]], dtype=bool)
    

提交回复
热议问题