0

I grouped my df into different ids:

df = [x for _, x in fulldf.groupby('ids')]

Now I get a list object of different data frames, each has a different size.

I wrote an own function which uses each grouped data frame as an input:

def myfunction(df):      
    A[1:,0]=df.A      
    A[0,0]=df.A+df.B

How can I know iterate through the data frames of the list? F.e.:

myfunction(df's of the list)

How can I do that? I hope that was clear enough.

Thanks,

KS

PS: the question relates to question Python: groupwise & recursive computation on pandas dataframe where one can find input & desired output.

Kosta S.
  • 339
  • 1
  • 2
  • 11
  • 2
    Why aren't you using `groupby.apply`? – cs95 Dec 19 '18 at 17:01
  • 4
    how about `[myfunction(x) for x in df]` ? – Yuca Dec 19 '18 at 17:01
  • 1
    Can you give a simple example of your input and desired output? – AmourK Dec 19 '18 at 17:05
  • I asked a similar question here already where one can find also the input & desireed output: https://stackoverflow.com/questions/53835485/python-groupwise-recursive-computation-on-pandas-dataframe?noredirect=1#comment94519759_53835485 – Kosta S. Dec 19 '18 at 17:07
  • can't vouch about it's efficiency though, maybe the link from jpp tells you more about it! – Yuca Dec 19 '18 at 17:15
  • @Yuca, No, my link is functionally equivalent to your suggestion. `groupby` + `apply` *may* be the best option here, but we need more information to confirm. – jpp Dec 19 '18 at 17:18
  • got it @jpp, thanks for the heads up – Yuca Dec 19 '18 at 17:20
  • @Yuca your first suggestion works perfectly. Not sure if it is the most efficient way but in a list of +6800 df with sizes of [100+,15] it computed it in seconds! Many thanks! – Kosta S. Dec 19 '18 at 17:31

0 Answers0