1

I have a table (simplified view) like this:

SellerID businessDate sales_total
A-123    1/1/2017     12.05
A-123    1/1/2017     126.75
B-223    1/1/2017     2.75
B-223    1/1/2017     31.75
C-444    1/1/2017     55.55
A-123    1/2/2017     12.05
A-123    1/2/2017     126.75
B-223    1/2/2017     10.75
C-444    1/2/2017     31.75
C-444    1/2/2017     55.55

And the data continues like that

What I would like to do is have the date values as the columns and the sales total for each SellerID as a single row like this:

SellerID  1/1/2017 1/2/2017 .....
A-123     300      100      .....
B-223     150      60       .....
C-444     120      55       .....
D-555     0        149      .....

My thinking is that I can easily find the daily best seller, and find the SellerID's who fall within below 3-std deviations of the mean for each selling day to find SellerID's who might not be performing well.

Thank you

5
  • 1
    Are the values count? or is that mean? If its plain pivoting read this stackoverflow.com/questions/47152691/how-to-pivot-a-dataframe Commented Nov 29, 2017 at 11:44
  • 1
    There is not possible use pivot_table df.pivot_table(index='SellerID', columns='businessDate', values='sales_total', aggfunc='sum')? Commented Nov 29, 2017 at 11:45
  • 1
    @jezrael I didn't realize there was a function to pivot! Commented Nov 29, 2017 at 11:47
  • @jezrael the df.pivot_table works great, if I want to get the mean of the counts with the aggfunc do I pass a list of strings? Commented Nov 29, 2017 at 14:03
  • @codebase5000 - there is not necessary aggfunc, because default aggfunc='mean' :) Commented Nov 29, 2017 at 14:04

1 Answer 1

1

Using pandas, one can easily pivot table a dataframe, for your specific example, one can solve it as in the image bellow:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

if I have another values column, can I specify that? like TaxTotal?
Ty - I do work out a lot.
This is concise and intuitive; beautiful brain of yours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.