Giter VIP home page Giter VIP logo

Comments (4)

jheer avatar jheer commented on May 14, 2024

I don’t think I fully understand what you are trying to accomplish and why you need params to do it. Can you provide a bit more detail about your task, the input, and the desired output?

from arquero.

dscape avatar dscape commented on May 14, 2024

Hi @jheer - first thanks for this. It's amazing, I was thinking of building a backend in python to use numpy but this really made prototyping some ideas so much quicker.

I made this observable notebook for you to take a peek, perhaps its clearer? I know how to do the JS bits, was just wondering what how to achieve this in Arquero?

https://observablehq.com/@dscape/alternative-to-a-fluent-api-16

from arquero.

jheer avatar jheer commented on May 14, 2024

I'm still not entirely sure what transformation logic you have in mind, but here is a guess.

staffAq
  .unroll({ month: d => op.sequence(0, 12) })
  .derive({ monthly: d => op.month(d.start) <= d.month ? d.monthly : 0 })
  .params({ names: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] })
  .derive({ month: (d, $) => $.names[d.month] })
  .groupby('name')
  .pivot('month', 'monthly', { sort: false })
  .select('name', 'Jan', 'Jul', 'Dec')
  .view()

The steps involved are:

  1. Add a new array from 0...11 for each month, and unroll it so we get one row per month.
  2. Rewrite the monthly column based on the start date.
  3. Bind a parameter: an array of month names to use as a lookup table
  4. Replace the month indices with month names
  5. Group-by the name column to prepare for the next step
  6. Pivot the table so that we map values for each month (per-row) to a new columns, one per month
  7. (Optionally) Add a select to map the output for your example. If you instead want to filter by some logic, you might include a filter before the pivot, as you see fit.

from arquero.

dscape avatar dscape commented on May 14, 2024

Thank you, this is excellent!

from arquero.

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.