What happens when you compare 2 pandas Series

后端 未结 1 993
再見小時候
再見小時候 2021-01-03 18:58

I ran up against unexpected behavior in pandas when comparing two series. I wanted to know if this is intended or a bug.

suppose I:

import pandas as         


        
1条回答
  •  别那么骄傲
    2021-01-03 19:31

    Bug or not. I would suggest to make a dataframe and compare the series inside the dataframe.

    import pandas as pd
    x = pd.Series([1, 1, 1, 0, 0, 0], index=['a', 'b', 'c', 'd', 'e', 'f'], name='Value_x')
    y = pd.Series([0, 2, 0, 2, 0, 2], index=['c', 'f', 'a', 'e', 'b', 'd'], name='Value_y')
    
    df = pd.DataFrame({"Value_x":x, "Value_y":y})
    df['Value_x'] > df['Value_y']
    
    Out[3]:
    
    a     True
    b     True
    c     True
    d    False
    e    False
    f    False
    dtype: bool
    

    0 讨论(0)
提交回复
热议问题