简体   繁体   English

concat和sum多索引熊猫系列

[英]concat and sum multiindex pandas series

Hi I have two pandas series 嗨,我有两个熊猫系列

series1 系列1

Company      Product      Price
ABC          Apple        1234
             Orange       123
BCD          Apple        123
PCT          Pineapple    434
             Beef         884    

series2 系列2

Company      Product      Price
BCD          Orange       751
PCT          Pineapple    632
             Orange       165            

I would like to concat the two series into a series 3 我想将两个系列合并为一个系列3

Company      Product      Price
ABC          Apple        1234
             Orange       123
BCD          Apple        123
             Orange       751
PCT          Pineapple    1066
             Orange       165
             Beef         884

I have tried to use 我尝试使用

series3 = pd.concat([series1,series2]).sum(level=1) 

However, it cannot produce what I want. 但是,它不能产生我想要的东西。 Thank you in advance 先感谢您

You could try using groupby 您可以尝试使用groupby

series3 = pd.concat([df,df1]).groupby(level=[0,1]).sum()

# Output: 


Company   Product     Price
ABC        Apple      1234
           Orange     123
BCD        Apple      123
           Orange     751
PCT        Beef       884
           Orange     165
           Pineapple  1066

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM