Skip to content Skip to sidebar Skip to footer

How To Do Intersection Of Dataframes In Pandas

I have a dataframe like following : The columns are : Title ASIN State SellerSKU Quantity FBAStock QuantityToShip I have another dataframe which contains a subse

Solution 1:

I believe want transform for new column by size per groups with multiple column Quantity by *=:

originalDF = pd.DataFrame({'State':list('aaabbb'),
                           'ASIN':list('cfcccc'),
                           'Quantity':[100] * 6})


originalDF['Quantity'] *= (originalDF.groupby(['State' ,'ASIN' , 'Quantity'])['State']
                                    .transform('size'))

print (originalDF)
  State ASIN  Quantity
0     a    c       2001     a    f       1002     a    c       2003     b    c       3004     b    c       3005     b    c       300

Detail:

print ((originalDF.groupby(['State' ,'ASIN' , 'Quantity'])['State']
                                    .transform('size')))

021122334353
Name: State, dtype: int64

Post a Comment for "How To Do Intersection Of Dataframes In Pandas"