Giter Club home page Giter Club logo

Comments (5)

nalimilan avatar nalimilan commented on June 22, 2024 1

aggregate is made to be used with a grouping variable. colwise! would just be an in-place equivalent of colwise, so something very simple. Cf. https://discourse.julialang.org/t/announcement-dataframes-future-plans/266/25.

Though thinking about it more, I'm not sure how useful such a function would be. colwise is mainly useful for summary functions which return one or two values for each column. OTC, colwise! would only work for functions which return the vectors or the same length as the input. So probably better give this function a different name.

The other issue with such a function is that colwise!(col -> col .- mean(col), df) it would encourage an inefficient pattern which allocates a copy of col before replacing the old column. A manual loop with x0 = mean(col); map!(x -> x - x0, col) is much more efficient in that regard. So if we offer such a helper function, it should be smarter than that. We could have it call the function for each element of a column, with additional column-wise arguments à la broadcast. For example: colwise!((x, x0) -> x - x0, df, colwise(mean, df).

from datatables.jl.

mkborregaard avatar mkborregaard commented on June 22, 2024 1

Reading your concerns here and thinking about it more, I am also not sure this functionality would be broadly useful. It came out of a natural impulse to work with a DataTable inplace because this is so ideomatic in julia.
Maybe if map! could simply take an eachcol iterator as argument?

from datatables.jl.

nalimilan avatar nalimilan commented on June 22, 2024 1

Leaving a breadcrumb to https://stackoverflow.com/questions/44235201/shortcut-to-transforming-a-dataframe, which provides an example of a use case for this.

from datatables.jl.

cjprybol avatar cjprybol commented on June 22, 2024

Are you imagining that colwise! would work like an in-place aggregate?

example:

julia> dt
10×2 DataTables.DataTable
│ Row │ A  │ B  │
├─────┼────┼────┤
│ 111  │
│ 222  │
│ 333  │
│ 444  │
│ 555  │
│ 666  │
│ 777  │
│ 888  │
│ 999  │
│ 101010 │

julia> colwise!(normalize, dt)
10×2 DataTables.DataTable
│ Row │ A         │ B         │
├─────┼───────────┼───────────┤
│ 10.05096470.0509647 │
│ 20.1019290.101929  │
│ 30.1528940.152894  │
│ 40.2038590.203859  │
│ 50.2548240.254824  │
│ 60.3057880.305788  │
│ 70.3567530.356753  │
│ 80.4077180.407718  │
│ 90.4586820.458682  │
│ 100.5096470.509647# compared to

julia> aggregate(dt, normalize)
10×2 DataTables.DataTable
│ Row │ A_normalize │ B_normalize │
├─────┼─────────────┼─────────────┤
│ 10.05096470.0509647   │
│ 20.1019290.101929    │
│ 30.1528940.152894    │
│ 40.2038590.203859    │
│ 50.2548240.254824    │
│ 60.3057880.305788    │
│ 70.3567530.356753    │
│ 80.4077180.407718    │
│ 90.4586820.458682    │
│ 100.5096470.509647

That should be pretty straight forward to do. What would be the preferable behavior for functions that reduce to scalars like sum/length or extrema? Fail on a dimension mismatch or resize the DataTable to be a single row? (I'm not sure if resize!(column, 1) will work, in which case it'd have to throw an error because it couldn't modify in place).

example

julia> colwise!(length, dt)
1×2 DataTables.DataTable
│ Row │ A  │ B  │
├─────┼────┼────┤
│ 11010# or
Error: DimensionMismatch: columns cannot be resized in place, use aggregate(function, dt) instead

from datatables.jl.

nalimilan avatar nalimilan commented on June 22, 2024

Yes, that would make sense. Maybe a bit surprising that you would be able to modify an iterator, but doesn't sound like a big issue.

from datatables.jl.

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.