Scaling Python with Dask by Holden Karau & Mika Kimmins
Author:Holden Karau & Mika Kimmins [Holden Karau]
Language: eng
Format: epub
Publisher: O'Reilly Media, Inc.
Published: 2023-07-25T00:00:00+00:00
Example 4-9. Dask custom aggregate
# Write a custom weighted mean, we get either a DataFrameGroupBy # with multiple columns or SeriesGroupBy for each chunk def process_chunk(chunk): def weighted_func(df): return (df["EmployerSize"] * df["DiffMeanHourlyPercent"]).sum() return (chunk.apply(weighted_func), chunk.sum()["EmployerSize"]) def agg(total, weights): return (total.sum(), weights.sum()) def finalize(total, weights): return total / weights weighted_mean = dd.Aggregation( name='weighted_mean', chunk=process_chunk, agg=agg, finalize=finalize) aggregated = (df_diff_with_emp_size.groupby("PostCode") ["EmployerSize", "DiffMeanHourlyPercent"].agg(weighted_mean))
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Access | Data Mining |
Data Modeling & Design | Data Processing |
Data Warehousing | MySQL |
Oracle | Other Databases |
Relational Databases | SQL |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8063)
Learning SQL by Alan Beaulieu(5746)
Weapons of Math Destruction by Cathy O'Neil(5421)
Azure Data and AI Architect Handbook by Olivier Mertens & Breght Van Baelen(5043)
Building Statistical Models in Python by Huy Hoang Nguyen & Paul N Adams & Stuart J Miller(5034)
Serverless Machine Learning with Amazon Redshift ML by Debu Panda & Phil Bates & Bhanu Pittampally & Sumeet Joshi(4916)
Data Wrangling on AWS by Navnit Shukla | Sankar M | Sam Palani(4683)
Driving Data Quality with Data Contracts by Andrew Jones(4620)
Big Data Analysis with Python by Ivan Marin(4393)
Machine Learning Model Serving Patterns and Best Practices by Md Johirul Islam(4375)
Data Engineering with dbt by Roberto Zagni(3435)
Blockchain Basics by Daniel Drescher(3077)
Solidity Programming Essentials by Ritesh Modi(3068)
Time Series Analysis with Python Cookbook by Tarek A. Atwan(2939)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2759)
Feature Store for Machine Learning by Jayanth Kumar M J(2687)
Learn T-SQL Querying by Pam Lahoud & Pedro Lopes(2670)
Pandas Cookbook by Theodore Petrou(2653)
Mastering Python for Finance by Unknown(2617)