DEV Community

Judy
Judy

Posted on

2 1 1 1 1

Group & Summarize a CSV File #eg68

Problem description & analysis

Below is CSV file sample.csv:

City,Year,Income

Delhi,2001,12345

Mumbai,2001,43211

Hyderabad,2001,54322

Delhi,2002,76543

Mumbai,2002,43211

Hyderabad,2002,54322

Bangalore,2001,43211

Bangalore,2001,54322

We are trying to group the file by City and calculate average of Income. Below is the desired result:

Bangalore - 48766

Delhi - 44444

Hyderabad - 54322

Mumbai - 43211

Solution

Write the script p1.dfx below in esProc:

Image description

=A1.groups(City;int(avg(Income))).(#1/" - "/#2)

Explanation

A1  Import the CSV file containing table headers.

A2  Group A1 by City and calculate average of Income, and output the grouped table sequence according to the desired format.

Read How to Call an SPL Script in Java to learn how to integrate the script code into a Java program.

SPL open source address

Download

API Trace View

Struggling with slow API calls?

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (1)

Collapse
 
esproc_spl profile image
Judy • Edited

Download it and try it, it will surprise you!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay