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 ar…


This content originally appeared on DEV Community and was authored by Judy

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


This content originally appeared on DEV Community and was authored by Judy


Print Share Comment Cite Upload Translate Updates
APA

Judy | Sciencx (2024-10-30T03:57:55+00:00) Group & Summarize a CSV File #eg68. Retrieved from https://www.scien.cx/2024/10/30/group-summarize-a-csv-file-eg68/

MLA
" » Group & Summarize a CSV File #eg68." Judy | Sciencx - Wednesday October 30, 2024, https://www.scien.cx/2024/10/30/group-summarize-a-csv-file-eg68/
HARVARD
Judy | Sciencx Wednesday October 30, 2024 » Group & Summarize a CSV File #eg68., viewed ,<https://www.scien.cx/2024/10/30/group-summarize-a-csv-file-eg68/>
VANCOUVER
Judy | Sciencx - » Group & Summarize a CSV File #eg68. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/30/group-summarize-a-csv-file-eg68/
CHICAGO
" » Group & Summarize a CSV File #eg68." Judy | Sciencx - Accessed . https://www.scien.cx/2024/10/30/group-summarize-a-csv-file-eg68/
IEEE
" » Group & Summarize a CSV File #eg68." Judy | Sciencx [Online]. Available: https://www.scien.cx/2024/10/30/group-summarize-a-csv-file-eg68/. [Accessed: ]
rf:citation
» Group & Summarize a CSV File #eg68 | Judy | Sciencx | https://www.scien.cx/2024/10/30/group-summarize-a-csv-file-eg68/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.