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.

[QST] Is there a way to do custom aggregations?

See original GitHub issue

For example I want to get the total progress within a group. My code looks like:

cols = ["user", "timecode", "published_at"]

aggs = {
        'timecode': ["first", "last"],
}

usages = cols >> nvt.ops.Groupby(
    groupby_cols="user"
    sort_cols=["published_at"],
    aggs=aggs,
    name_sep="_")

dataset = nvt.Dataset(data)
workflow = nvt.Workflow(all_feats)
sessions_gdf = workflow.fit_transform(dataset).to_ddf()
sessions_gdf["progress"] = sessions_gdf.progress_last - sessions_gdf.progress_first

Is there a way to include the subtraction into the workflow? I tested a couple of things like:

aggs = {
        'progress': [nvt.ops.LambdaOp(lambda col: col.last() - col.first())],
}

or

aggs = {
        'progress': [lambda col: col.last() - col.first()]
}

but neither seems to be supported. Is there another way to express this?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
krlngcommented, Oct 19, 2021

Thanks, that looks great, will try that!

0reactions
rnyakcommented, Oct 18, 2021

@krlng is the workaround above works for you? can we close this issue? thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[QST] Is there a way to do custom aggregations? #1164 - GitHub
For example I want to get the total progress within a group. My code looks like: cols = ["user", "timecode", "published_at"] aggs ...
Read more >
Creating Custom Aggregations to Use with Pandas groupby
A simple way to apply these aggregations is to create a list and pass that list as an argument. This method will apply...
Read more >
Implementing Custom Aggregations | TensorFlow Federated
In this tutorial, we explain design principles behind the tff.aggregators module and best practices for implementing custom aggregation of values from ...
Read more >
Aggregate functions - Amazon QuickSight - AWS Documentation
Custom aggregations can 't contain both aggregated and nonaggregated fields, in any combination. For example, this formula doesn't work: Sum(sales)+quantity .
Read more >
Write custom aggregation function in Pandas - GeeksforGeeks
Now, let's perform some operations: 1. Performing aggregation over the rows: This performs aggregate functions over the rows of the Dataframe.
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