question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Group dataset with different series

See original GitHub issue

I have the following dataset:

    this.data = [
      { discipline: 1, originalBudgetDollars: 1114.96 },
      { discipline: 2, originalBudgetDollars: 192 },
      { discipline: 1, expendedDollars: 1137.24 },
      { discipline: 2, expendedDollars: 55.08 },
      { discipline: 1, forecastAtCompletionDollars: 1276.62 },
      { discipline: 2, forecastAtCompletionDollars: 96 },
      { discipline: 1, earnedValueDollars: 81.6 },
      { discipline: 2, earnedValueDollars: 10636.6 }
    ];

I would like to end up with the following dataset:

NOTE: the resulting dataset has a new column (remainingDollars) which is the difference between originalBudgetDollars and expendedDollars.

    this.data = [
      { discipline: 1, originalBudgetDollars: 1114.96, expendedDollars: 1137.24, remainingDollars: -22.28, forecastAtCompletionDollars: 1276.62, earnedValueDollars: 81.6 },
      { discipline: 2, originalBudgetDollars: 192, expendedDollars: 55.08,  remainingDollars: 136.92, forecastAtCompletionDollars: 96, earnedValueDollars: 10636.6 },
    ];

Is there a way to group on a series (e.g. discipline) while maintaining all of the unique series, and for icing on the cake… add a new series which is the result of a function?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tunnelingcommented, Mar 30, 2021

Works like a charm! Thank you.

0reactions
ashleydaviscommented, Feb 15, 2022

Another thing is that you could dynamically generate allCols using Object.entries:

return new DataFrame(array)
  .groupBy((row) => row.discipline)
    .select((group) => {
          let allCols = {}
          // Known parameters
          const first = group.first();
          for (const [key, value] of Object.keys(first)) {
              allCols[key] = first[key];
          }
          // Unknown or "dynamic" parameters
          _.forEach(group.toArray(), function(value, key){
            allCols[value.parameter] = value.value
          })
          return allCols;
        })
    })
    .inflate()
    .orderBy(row => row.discipline)
    .toArray();
Read more comments on GitHub >

github_iconTop Results From Across the Web

IMS 14 - Database administration - Multiple data set groups
The following database types support multiple data set groups: HDAM; PHDAM; HIDAM; PHIDAM. When storing a database on multiple data sets, the terms...
Read more >
pandas GroupBy: Your Guide to Grouping Data in Python
You'll work with real-world datasets and chain GroupBy methods together to get ... A list of multiple column names; A dict or pandas...
Read more >
Grouping and Sampling Time Series Data | by Shelvi Garg
Time-stamped is data collected at different points in time. ... Try and experiment your own with some cool time series dataset including weather...
Read more >
Pandas - Groupby multiple values and plotting results
In this article, we will learn how to groupby multiple values and plotting the results in one go. Here, we take “exercise.csv” file...
Read more >
Group by: split-apply-combine — pandas 1.5.2 documentation
This is included in GroupBy as the size method. It returns a Series whose index are the group names and whose values are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found