Search code examples
reactjsdanfojs

How can I obtain the column values of a DataFrame in Danfojs?


I am using the package Danfojs in React. I have a dataframe where I'd like to obtain the values of a column as an array. If I try with df.values, I get an array of arrays, where each array is a row not a column. This is my code, note that I'm also performing other actions:

import * as dfd from 'danfojs/src/index'

const data = {'state':["todo","todo","done","done","doing","doing"]
const df = new dfd.DataFrame(data)
const df_sub = df.groupby(['state']).col(['state']).count()
const df_grouped = df_sub.loc({columns:['state_count']})
df_grouped.print()
console.log(df_grouped.values)

The output is:

╔═══╤═══════════════════╗
║   │ state_count       ║
╟───┼───────────────────╢
║ 0 │ 2                 ║
╟───┼───────────────────╢
║ 1 │ 2                 ║
╟───┼───────────────────╢
║ 2 │ 2                 ║
╚═══╧═══════════════════╝

[[2],[2],[2]]

The expected output is:

[2,2,2]

I.e., I'd like to do something similar to pandas df['column'].to_list()


Solution

  • Ok, it is already implemented but I couldn't find it in the documentation. It is as simple as: df['column'].values