Pandas join/merge/concat two dataframes

前端 未结 2 737
挽巷
挽巷 2020-11-30 08:50

I am having issues with joins in pandas and I am trying to figure out what is wrong. Say I have a dataframe x:



        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 09:15

    Does your index have duplicates x.index.is_unique? If so would explain the behavior you're seeing:

    In [16]: left
    Out[16]: 
                a
    2000-01-01  1
    2000-01-01  1
    2000-01-01  1
    2000-01-02  2
    2000-01-02  2
    2000-01-02  2
    
    In [17]: right
    Out[17]: 
                b
    2000-01-01  3
    2000-01-01  3
    2000-01-01  3
    2000-01-02  4
    2000-01-02  4
    2000-01-02  4
    
    In [18]: left.join(right)
    Out[18]: 
                a  b
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-01  1  3
    2000-01-02  2  4
    2000-01-02  2  4
    2000-01-02  2  4
    2000-01-02  2  4
    2000-01-02  2  4
    2000-01-02  2  4
    2000-01-02  2  4
    2000-01-02  2  4
    2000-01-02  2  4
    

提交回复
热议问题