Replies: 10 comments
-
| That's strange! Can you please provide a copy of your code and data so I can try running it and see if I can find the bug. | 
Beta Was this translation helpful? Give feedback.
-
| // Import modules
const dataForge = require("data-forge");
require("data-forge-fs");
// Path to CSV file
const csvFilePath = "sample_file.csv";
// Load the CSV file into a data frame
const dataFrame = dataForge.readFileSync(csvFilePath).parseCSV();
console.log(dataFrame)
// Group the data by column 'product' and aggregate
const aggregatedData = dataFrame
    .groupBy((row) => row.product)
    .select((group) => ({
        product: group.first().product,
        count: group.count(),
        averagePrice: group.deflate((row) => row.price).average(),
        maxPrice: group.deflate((row) => row.price).max(),
        minPrice: group.deflate((row) => row.price).min(),
    }))
    .inflate();
// Display the aggregated data in the console
console.log(aggregatedData.toArray()); | 
Beta Was this translation helpful? Give feedback.
-
| Data as well pls. | 
Beta Was this translation helpful? Give feedback.
-
| date, product, price, quantity | 
Beta Was this translation helpful? Give feedback.
-
| I think this is because the average function is being run on strings! You haven't parsed you CSV file correctly. Here's what it looks like for me in Data-Forge Notebook, I've highlighted the code you must add that it shows the correct results: | 
Beta Was this translation helpful? Give feedback.
-
| I've published a new version 1.10.0 that throws an exception if you try to use the maths functions on a series containing strings (or any type other than numbers). This will ensure no else suffers this confusion. Thanks so much for your contribution @triposat | 
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
| Can anyone help me, please? | 
Beta Was this translation helpful? Give feedback.
-
| Can anyone help me, please? | 
Beta Was this translation helpful? Give feedback.
-
| If you believe there is a bug please submit and an issue with example code. If you'd like to contribute please fix the problem and submit a PR. | 
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
My CSV File:
Code:
Output:
Why average is wrong ❌? And how to find the correct sum also?
The average should be: 3.5
Beta Was this translation helpful? Give feedback.
All reactions