How to merge a Series and DataFrame

前端 未结 6 1558
别跟我提以往
别跟我提以往 2020-12-02 08:30

If you came here looking for information on how to merge a DataFrame and Series on the index, please look at this answe

6条回答
  •  孤街浪徒
    2020-12-02 08:42

    Update
    From v0.24.0 onwards, you can merge on DataFrame and Series as long as the Series is named.

    df.merge(s.rename('new'), left_index=True, right_index=True)
    # If series is already named,
    # df.merge(s, left_index=True, right_index=True)
    

    Nowadays, you can simply convert the Series to a DataFrame with to_frame(). So (if joining on index):

    df.merge(s.to_frame(), left_index=True, right_index=True)
    

提交回复
热议问题