简体   繁体   中英

Merge dataframes in pandas

I have two dataframes in python

1)salespersoncount

在此处输入图片说明

2)salesdata

在此处输入图片说明

I want to merge both tables on country and repeat salesdata no of time value of salesperson in salespersoncount and repeat this n times which will be an input and the final output should look like:

在此处输入图片说明

Can anyone please guide on above steps?

您可以像这样执行连接:

salespersoncount.join(salesdata.set_index('Country'), on='Country')
x=pd.merge(df1,df2,left_on='Country',right_on='Country',how='inner')
x=x.loc[x.index.repeat(x['SalesPers'])]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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