Add a compute column to a csv file
The csv file below stores assessment parameters:
Lab Exercise,Long Quiz,Alternative Assessment 35,91,24 53,63,73 13,23,33 |
Use Java to do this: Compute Final Grade (the 4th column) value according to the existing 3 columns using the formula Lab Exercise * 30% + Long Quiz * 30% + Alternative Assessment * 40%, and write the result to a new csv file.
Lab Exercise,Long Quiz,Alternative Assessment,Final Grade 35,91,24,47.4 53,63,73,64.0 13,23,33,24.0 |
Write the following SPL code:
1 |
=T("d:/data.csv") |
2 |
=A2.derive('Lab Exercise' * 0.3 + 'Long Quiz' * 0.3 + 'Alternative Assessment' * 0.4:'Final Grade') |
3 |
=T("d:/result.csv":A3) |
T()function parses a csv file or generates a new one. derive() function adds a compute column.
Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.
Source:https://stackoverflow.com/questions/71971328/how-do-i-manipulate-a-csv-file
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL