Pandas映射数据框列

2024-06-16 10:51:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我的输入数据帧如下所示:

Store  PG1       PG2              PG3                      PG4
500    1 Women   02 Shirts        02 S-S_Woven_Shirts      02 Checked-Striped-
552    2 Baby
600    4 Boys    00 Denim All
704    5 Girls   01 Jackets       15 Woven blouses, tops


Store      MinThreshold   MaxThreshold   PG1       PG2               PG3                      PG4   
552        0              10             2 Baby
552        2              15             2 Baby    00 Denim All
600        3              16             5 Girls
600        4              17             4 Boys    00 Denim All
704        5              18             5 Girls   01 Jackets        15 Woven blouses, tops
704        10             20             0 Men     00 Denim_Bottoms  02 Capris   
500        6              19             1 Women   02 Shirts         02 S-S_Woven_Shirts      02 Checked-Striped-Patterned_Shirts-Tops-Blouses

期望输出为

Store  PG1      PG2             PG3                   PG4                 MinThreshold  MaxThreshold                    
500    1 Women  02 Shirts       02 S-S_Woven_Shirts   02 Checked-Striped- 6             19
552    2 Baby                                                             2             15
600    4 Boys   00 Denim All                                              4             17
704    5 Girls  01 Jackets      15 Woven blouses, tops                    5             18

我想根据“存储”、“PG1”、“PG2”、“PG3”和“PG4”将阈值从第二个数据帧添加到第一个数据帧中

我试过这个

df1 = pd.merge(df1, df2,  how='left',
 left_on=["Store","PG1","PG2","PG3","PG4"], right_on =["Store","PG1","PG2","PG3","PG4"])

你能帮我一下吗


Tags: 数据storeallbabycheckedgirlsshirtswoven