Code Monkey home page Code Monkey logo

Comments (2)

pwwang avatar pwwang commented on August 11, 2024

Looks like you want to get the number of rows of nested frames in column data2?

f.data2.size (you should actually do f.data2.size() is getting the sizes of the series in each group, which are all 1's.

What you need to do is:

>>> df = (
...     df1
...     >> nest_join(df2)
...     >> rename(data2=f._y_joined)
...     >> group_by(f.x)
...     >> mutate(ct=f.data2.transform(lambda x: nrow(x.iloc[0])))
...     >> ungroup()
... )
>>> df
        x     data1     data2      ct
  <int64>  <object>  <object> <int64>
0       1  <DF 1x2>  <DF 1x1>       1
1       2  <DF 1x2>  <DF 1x1>       1
2       3  <DF 1x2>  <DF 0x1>       0
3       4  <DF 1x2>  <DF 0x1>       0

Explanation on mutate(ct=f.data2.transform(lambda x: nrow(x.iloc[0]))):

  • f.data2 is the column with the nested frames, and it is evaluated as a SeriesGroupBy object, since the entire frame is grouped
  • .transform() is to transform the nested frames into their corresponding # rows
  • lambda x: nrow(x.iloc[0])) is to get the # rows of the nested frames in each group in that f.data2 column. Note that x is a Series object with the nested frame as the only element. However, the index of the object is from 0 to 3 in each group, we can't use x[0] directly to get the element, instead, we need x.iloc[0].

from datar.

cah-dipanjan avatar cah-dipanjan commented on August 11, 2024

Thanks a lot for the explanation!

from datar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.