Search code examples
dataframe-js

How can I get all column values in dataframe-js as array?


I use dataframe-js to create a dataframe like this:

const df = new DataFrame({
    column1: [3, 6, 8], // <------ A column
    column2: [3, 4, 5, 6],
}, ['column1', 'column2']);

How can I access / print an array containing all column1 values (in this case: [3, 6, 8]) ?


Solution

  • I just figured out that this should do the job:

    const column1 = df.toArray('column1')
    

    And to calculate a sum of all column1 values:

    var sum = df.reduce((p, n) => n.get('column1') + p, 0)