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

1k views Asked by At

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]) ?

2

There are 2 answers

0
Tony On BEST ANSWER

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)
1
Dhananjai Pai On

From the documentation you mentioned, the following code should work.

const column1Array = df.select("column1").toArray();;