Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Indexing with multiple keys

  PageId    VolumePred  ConversionPred  OSBrowser
    955761  37200.0      27625.0    (11, 16)
    955764  30157.0      21155.0    (11, 16)
    955764  25258.0      17836.0    (11, 16)
    1184903 35492.0      17768.0    (11, 16)
    955764  24683.0      16965.0    (11, 16)
    955764  8.0              0.0    (32, 16)
    955761  4.0              0.0    (33, 16)
    955761  4.0              0.0    (33, 16)

I try to sum of VolumePred and ConversionPred by PageID and OSBrowser.

So here for example , the needed result should be :

  PageId    VolumePred  ConversionPred  OSBrowser
    955761  37200.0      27625.0       (11, 16)
    955764  55415.0      38991.0       (11, 16)
   1184903  35492.0      17768.0       (11, 16)
    955764  24683.0      16965.0       (11, 16)
    955764  8.0              0.0       (32, 16)
    955761  8.0              0.0       (33, 16)

I tryied with this code :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

subdata.groupby(['PageId', 'OSBrowser'])['ConversionPred', 'VolumePred'].agg('sum')

but i get this warning :

/tmp/ipykernel_16715/1460716585.py:1: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
  subdata.groupby(['PageId', 'OSBrowser'])['ConversionPred', 'VolumePred'].agg('sum')

Any idea please? thanks

>Solution :

You’re really close; you just need to add an extra set of square brackets:

subdata.groupby(['PageId', 'OSBrowser'])[['ConversionPred', 'VolumePred']].agg('sum')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading