How to Group by column value in Pandas Data frame










4














I have pandas dataframe like this. I want group by App_Name in seperate variable



App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.orange.thescore 2018-10-13 2034.611964 8273607
com.number.studio 2018-10-13 1807.756545 33736740
com.orange.thescore 2018-10-14 4671.930435 38575556
com.number.studio 2018-10-14 3533.461547 38726087
com.banana.com 2018-10-14 2920.33747 86230313
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.number.studio 2018-10-15 2044.759823 76526368
com.apple.tiles2 2018-10-16 2610.214035 30611434
com.alpha.studio 2018-10-16 1731.429858 11643154
com.banana.com 2018-10-16 1601.387403 13781285
com.alpha.studio 2018-10-17 2769.373388 13198984
com.banana.com 2018-10-17 2205.359489 21974901
com.orange.thescore 2018-10-17 1820.852862 7565015
com.alpha.studio 2018-10-18 2784.822039 24217875
com.banana.com 2018-10-18 2545.899329 28361412
com.orange.thescore 2018-10-18 2052.207745 7544861


I want to group data by App_Name and stored in sepearte list or dataframe for each App_Name, something like this given below:



App_Name Date Response Gross Revenue
com.alpha.studio 2018-10-16 1731.429858 11643154
com.alpha.studio 2018-10-17 2769.373388 13198984
com.alpha.studio 2018-10-18 2784.822039 24217875

App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.apple.tiles2 2018-10-16 2610.214035 30611434

App_Name Date Response Gross Revenue
com.banana.com 2018-10-14 2920.33747 86230313
com.banana.com 2018-10-16 1601.387403 13781285
com.banana.com 2018-10-17 2205.359489 21974901
com.banana.com 2018-10-18 2545.899329 28361412

App_Name Date Response Gross Revenue
com.number.studio 2018-10-14 3533.461547 38726087
com.number.studio 2018-10-13 1807.756545 33736740
com.number.studio 2018-10-15 2044.759823 76526368

App_Name Date Response Gross Revenue
com.orange.thescore 2018-10-13 2034.611964 8273607
com.orange.thescore 2018-10-14 4671.930435 38575556
com.orange.thescore 2018-10-17 1820.852862 7565015
com.orange.thescore 2018-10-18 2052.207745 7544861









share|improve this question

















  • 1




    df.groupby('App_Name')?
    – juanpa.arrivillaga
    Nov 12 at 10:21






  • 5




    I'd like to know how this question has 4 upvotes in 3 minutes.
    – coldspeed
    Nov 12 at 10:22















4














I have pandas dataframe like this. I want group by App_Name in seperate variable



App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.orange.thescore 2018-10-13 2034.611964 8273607
com.number.studio 2018-10-13 1807.756545 33736740
com.orange.thescore 2018-10-14 4671.930435 38575556
com.number.studio 2018-10-14 3533.461547 38726087
com.banana.com 2018-10-14 2920.33747 86230313
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.number.studio 2018-10-15 2044.759823 76526368
com.apple.tiles2 2018-10-16 2610.214035 30611434
com.alpha.studio 2018-10-16 1731.429858 11643154
com.banana.com 2018-10-16 1601.387403 13781285
com.alpha.studio 2018-10-17 2769.373388 13198984
com.banana.com 2018-10-17 2205.359489 21974901
com.orange.thescore 2018-10-17 1820.852862 7565015
com.alpha.studio 2018-10-18 2784.822039 24217875
com.banana.com 2018-10-18 2545.899329 28361412
com.orange.thescore 2018-10-18 2052.207745 7544861


I want to group data by App_Name and stored in sepearte list or dataframe for each App_Name, something like this given below:



App_Name Date Response Gross Revenue
com.alpha.studio 2018-10-16 1731.429858 11643154
com.alpha.studio 2018-10-17 2769.373388 13198984
com.alpha.studio 2018-10-18 2784.822039 24217875

App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.apple.tiles2 2018-10-16 2610.214035 30611434

App_Name Date Response Gross Revenue
com.banana.com 2018-10-14 2920.33747 86230313
com.banana.com 2018-10-16 1601.387403 13781285
com.banana.com 2018-10-17 2205.359489 21974901
com.banana.com 2018-10-18 2545.899329 28361412

App_Name Date Response Gross Revenue
com.number.studio 2018-10-14 3533.461547 38726087
com.number.studio 2018-10-13 1807.756545 33736740
com.number.studio 2018-10-15 2044.759823 76526368

App_Name Date Response Gross Revenue
com.orange.thescore 2018-10-13 2034.611964 8273607
com.orange.thescore 2018-10-14 4671.930435 38575556
com.orange.thescore 2018-10-17 1820.852862 7565015
com.orange.thescore 2018-10-18 2052.207745 7544861









share|improve this question

















  • 1




    df.groupby('App_Name')?
    – juanpa.arrivillaga
    Nov 12 at 10:21






  • 5




    I'd like to know how this question has 4 upvotes in 3 minutes.
    – coldspeed
    Nov 12 at 10:22













4












4








4







I have pandas dataframe like this. I want group by App_Name in seperate variable



App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.orange.thescore 2018-10-13 2034.611964 8273607
com.number.studio 2018-10-13 1807.756545 33736740
com.orange.thescore 2018-10-14 4671.930435 38575556
com.number.studio 2018-10-14 3533.461547 38726087
com.banana.com 2018-10-14 2920.33747 86230313
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.number.studio 2018-10-15 2044.759823 76526368
com.apple.tiles2 2018-10-16 2610.214035 30611434
com.alpha.studio 2018-10-16 1731.429858 11643154
com.banana.com 2018-10-16 1601.387403 13781285
com.alpha.studio 2018-10-17 2769.373388 13198984
com.banana.com 2018-10-17 2205.359489 21974901
com.orange.thescore 2018-10-17 1820.852862 7565015
com.alpha.studio 2018-10-18 2784.822039 24217875
com.banana.com 2018-10-18 2545.899329 28361412
com.orange.thescore 2018-10-18 2052.207745 7544861


I want to group data by App_Name and stored in sepearte list or dataframe for each App_Name, something like this given below:



App_Name Date Response Gross Revenue
com.alpha.studio 2018-10-16 1731.429858 11643154
com.alpha.studio 2018-10-17 2769.373388 13198984
com.alpha.studio 2018-10-18 2784.822039 24217875

App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.apple.tiles2 2018-10-16 2610.214035 30611434

App_Name Date Response Gross Revenue
com.banana.com 2018-10-14 2920.33747 86230313
com.banana.com 2018-10-16 1601.387403 13781285
com.banana.com 2018-10-17 2205.359489 21974901
com.banana.com 2018-10-18 2545.899329 28361412

App_Name Date Response Gross Revenue
com.number.studio 2018-10-14 3533.461547 38726087
com.number.studio 2018-10-13 1807.756545 33736740
com.number.studio 2018-10-15 2044.759823 76526368

App_Name Date Response Gross Revenue
com.orange.thescore 2018-10-13 2034.611964 8273607
com.orange.thescore 2018-10-14 4671.930435 38575556
com.orange.thescore 2018-10-17 1820.852862 7565015
com.orange.thescore 2018-10-18 2052.207745 7544861









share|improve this question













I have pandas dataframe like this. I want group by App_Name in seperate variable



App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.orange.thescore 2018-10-13 2034.611964 8273607
com.number.studio 2018-10-13 1807.756545 33736740
com.orange.thescore 2018-10-14 4671.930435 38575556
com.number.studio 2018-10-14 3533.461547 38726087
com.banana.com 2018-10-14 2920.33747 86230313
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.number.studio 2018-10-15 2044.759823 76526368
com.apple.tiles2 2018-10-16 2610.214035 30611434
com.alpha.studio 2018-10-16 1731.429858 11643154
com.banana.com 2018-10-16 1601.387403 13781285
com.alpha.studio 2018-10-17 2769.373388 13198984
com.banana.com 2018-10-17 2205.359489 21974901
com.orange.thescore 2018-10-17 1820.852862 7565015
com.alpha.studio 2018-10-18 2784.822039 24217875
com.banana.com 2018-10-18 2545.899329 28361412
com.orange.thescore 2018-10-18 2052.207745 7544861


I want to group data by App_Name and stored in sepearte list or dataframe for each App_Name, something like this given below:



App_Name Date Response Gross Revenue
com.alpha.studio 2018-10-16 1731.429858 11643154
com.alpha.studio 2018-10-17 2769.373388 13198984
com.alpha.studio 2018-10-18 2784.822039 24217875

App_Name Date Response Gross Revenue
com.apple.tiles2 2018-10-13 3748.723574 24133394
com.apple.tiles2 2018-10-15 3986.434851 35928884
com.apple.tiles2 2018-10-16 2610.214035 30611434

App_Name Date Response Gross Revenue
com.banana.com 2018-10-14 2920.33747 86230313
com.banana.com 2018-10-16 1601.387403 13781285
com.banana.com 2018-10-17 2205.359489 21974901
com.banana.com 2018-10-18 2545.899329 28361412

App_Name Date Response Gross Revenue
com.number.studio 2018-10-14 3533.461547 38726087
com.number.studio 2018-10-13 1807.756545 33736740
com.number.studio 2018-10-15 2044.759823 76526368

App_Name Date Response Gross Revenue
com.orange.thescore 2018-10-13 2034.611964 8273607
com.orange.thescore 2018-10-14 4671.930435 38575556
com.orange.thescore 2018-10-17 1820.852862 7565015
com.orange.thescore 2018-10-18 2052.207745 7544861






python pandas pandas-groupby data-science






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 10:18









hepiz

1478




1478







  • 1




    df.groupby('App_Name')?
    – juanpa.arrivillaga
    Nov 12 at 10:21






  • 5




    I'd like to know how this question has 4 upvotes in 3 minutes.
    – coldspeed
    Nov 12 at 10:22












  • 1




    df.groupby('App_Name')?
    – juanpa.arrivillaga
    Nov 12 at 10:21






  • 5




    I'd like to know how this question has 4 upvotes in 3 minutes.
    – coldspeed
    Nov 12 at 10:22







1




1




df.groupby('App_Name')?
– juanpa.arrivillaga
Nov 12 at 10:21




df.groupby('App_Name')?
– juanpa.arrivillaga
Nov 12 at 10:21




5




5




I'd like to know how this question has 4 upvotes in 3 minutes.
– coldspeed
Nov 12 at 10:22




I'd like to know how this question has 4 upvotes in 3 minutes.
– coldspeed
Nov 12 at 10:22












1 Answer
1






active

oldest

votes


















3














Convert groupby object to dictionary of DataFrames:



d = dict(tuple(df.groupby('App_Name')))

print (d['com.alpha.studio'])
App_Name Date Response Gross Revenue
9 com.alpha.studio 2018-10-16 1731.429858 11643154 NaN
11 com.alpha.studio 2018-10-17 2769.373388 13198984 NaN
14 com.alpha.studio 2018-10-18 2784.822039 24217875 NaN


EDIT:



d1 = 
for k, v in d.items():
d1[k] = v['Gross Revenue'].rolling(2).mean()





share|improve this answer


















  • 2




    do you have any idea why dict(df.groupby('App_Name') is giving an TypeError: attribute of type 'str' is not callable error? It's very strange
    – juanpa.arrivillaga
    Nov 12 at 10:32










  • @juanpa.arrivillaga - Sorry, not idea.
    – jezrael
    Nov 12 at 11:03










  • @ jezrael I want to calculate the rolling mean for gross revenue and store separately date frame with calculated mean and corresponding date. can please help in it
    – hepiz
    Nov 13 at 12:22







  • 1




    What is formula for standard DataFrame?
    – jezrael
    Nov 13 at 12:22







  • 1




    @hamsa - check edited answer. Is possible loop by each DataFrame, caunt values and append back.
    – jezrael
    Nov 13 at 12:37










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260050%2fhow-to-group-by-column-value-in-pandas-data-frame%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Convert groupby object to dictionary of DataFrames:



d = dict(tuple(df.groupby('App_Name')))

print (d['com.alpha.studio'])
App_Name Date Response Gross Revenue
9 com.alpha.studio 2018-10-16 1731.429858 11643154 NaN
11 com.alpha.studio 2018-10-17 2769.373388 13198984 NaN
14 com.alpha.studio 2018-10-18 2784.822039 24217875 NaN


EDIT:



d1 = 
for k, v in d.items():
d1[k] = v['Gross Revenue'].rolling(2).mean()





share|improve this answer


















  • 2




    do you have any idea why dict(df.groupby('App_Name') is giving an TypeError: attribute of type 'str' is not callable error? It's very strange
    – juanpa.arrivillaga
    Nov 12 at 10:32










  • @juanpa.arrivillaga - Sorry, not idea.
    – jezrael
    Nov 12 at 11:03










  • @ jezrael I want to calculate the rolling mean for gross revenue and store separately date frame with calculated mean and corresponding date. can please help in it
    – hepiz
    Nov 13 at 12:22







  • 1




    What is formula for standard DataFrame?
    – jezrael
    Nov 13 at 12:22







  • 1




    @hamsa - check edited answer. Is possible loop by each DataFrame, caunt values and append back.
    – jezrael
    Nov 13 at 12:37















3














Convert groupby object to dictionary of DataFrames:



d = dict(tuple(df.groupby('App_Name')))

print (d['com.alpha.studio'])
App_Name Date Response Gross Revenue
9 com.alpha.studio 2018-10-16 1731.429858 11643154 NaN
11 com.alpha.studio 2018-10-17 2769.373388 13198984 NaN
14 com.alpha.studio 2018-10-18 2784.822039 24217875 NaN


EDIT:



d1 = 
for k, v in d.items():
d1[k] = v['Gross Revenue'].rolling(2).mean()





share|improve this answer


















  • 2




    do you have any idea why dict(df.groupby('App_Name') is giving an TypeError: attribute of type 'str' is not callable error? It's very strange
    – juanpa.arrivillaga
    Nov 12 at 10:32










  • @juanpa.arrivillaga - Sorry, not idea.
    – jezrael
    Nov 12 at 11:03










  • @ jezrael I want to calculate the rolling mean for gross revenue and store separately date frame with calculated mean and corresponding date. can please help in it
    – hepiz
    Nov 13 at 12:22







  • 1




    What is formula for standard DataFrame?
    – jezrael
    Nov 13 at 12:22







  • 1




    @hamsa - check edited answer. Is possible loop by each DataFrame, caunt values and append back.
    – jezrael
    Nov 13 at 12:37













3












3








3






Convert groupby object to dictionary of DataFrames:



d = dict(tuple(df.groupby('App_Name')))

print (d['com.alpha.studio'])
App_Name Date Response Gross Revenue
9 com.alpha.studio 2018-10-16 1731.429858 11643154 NaN
11 com.alpha.studio 2018-10-17 2769.373388 13198984 NaN
14 com.alpha.studio 2018-10-18 2784.822039 24217875 NaN


EDIT:



d1 = 
for k, v in d.items():
d1[k] = v['Gross Revenue'].rolling(2).mean()





share|improve this answer














Convert groupby object to dictionary of DataFrames:



d = dict(tuple(df.groupby('App_Name')))

print (d['com.alpha.studio'])
App_Name Date Response Gross Revenue
9 com.alpha.studio 2018-10-16 1731.429858 11643154 NaN
11 com.alpha.studio 2018-10-17 2769.373388 13198984 NaN
14 com.alpha.studio 2018-10-18 2784.822039 24217875 NaN


EDIT:



d1 = 
for k, v in d.items():
d1[k] = v['Gross Revenue'].rolling(2).mean()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 at 12:36

























answered Nov 12 at 10:30









jezrael

319k22258337




319k22258337







  • 2




    do you have any idea why dict(df.groupby('App_Name') is giving an TypeError: attribute of type 'str' is not callable error? It's very strange
    – juanpa.arrivillaga
    Nov 12 at 10:32










  • @juanpa.arrivillaga - Sorry, not idea.
    – jezrael
    Nov 12 at 11:03










  • @ jezrael I want to calculate the rolling mean for gross revenue and store separately date frame with calculated mean and corresponding date. can please help in it
    – hepiz
    Nov 13 at 12:22







  • 1




    What is formula for standard DataFrame?
    – jezrael
    Nov 13 at 12:22







  • 1




    @hamsa - check edited answer. Is possible loop by each DataFrame, caunt values and append back.
    – jezrael
    Nov 13 at 12:37












  • 2




    do you have any idea why dict(df.groupby('App_Name') is giving an TypeError: attribute of type 'str' is not callable error? It's very strange
    – juanpa.arrivillaga
    Nov 12 at 10:32










  • @juanpa.arrivillaga - Sorry, not idea.
    – jezrael
    Nov 12 at 11:03










  • @ jezrael I want to calculate the rolling mean for gross revenue and store separately date frame with calculated mean and corresponding date. can please help in it
    – hepiz
    Nov 13 at 12:22







  • 1




    What is formula for standard DataFrame?
    – jezrael
    Nov 13 at 12:22







  • 1




    @hamsa - check edited answer. Is possible loop by each DataFrame, caunt values and append back.
    – jezrael
    Nov 13 at 12:37







2




2




do you have any idea why dict(df.groupby('App_Name') is giving an TypeError: attribute of type 'str' is not callable error? It's very strange
– juanpa.arrivillaga
Nov 12 at 10:32




do you have any idea why dict(df.groupby('App_Name') is giving an TypeError: attribute of type 'str' is not callable error? It's very strange
– juanpa.arrivillaga
Nov 12 at 10:32












@juanpa.arrivillaga - Sorry, not idea.
– jezrael
Nov 12 at 11:03




@juanpa.arrivillaga - Sorry, not idea.
– jezrael
Nov 12 at 11:03












@ jezrael I want to calculate the rolling mean for gross revenue and store separately date frame with calculated mean and corresponding date. can please help in it
– hepiz
Nov 13 at 12:22





@ jezrael I want to calculate the rolling mean for gross revenue and store separately date frame with calculated mean and corresponding date. can please help in it
– hepiz
Nov 13 at 12:22





1




1




What is formula for standard DataFrame?
– jezrael
Nov 13 at 12:22





What is formula for standard DataFrame?
– jezrael
Nov 13 at 12:22





1




1




@hamsa - check edited answer. Is possible loop by each DataFrame, caunt values and append back.
– jezrael
Nov 13 at 12:37




@hamsa - check edited answer. Is possible loop by each DataFrame, caunt values and append back.
– jezrael
Nov 13 at 12:37

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260050%2fhow-to-group-by-column-value-in-pandas-data-frame%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto