1

I understood Danfo.js is the Javascript equivalent to Pandas. Now I have a Danfo dataframe and want to change the cell at row i and column "name". In pandas I would use

df.at(i,'name') = new_value

However with Danfo I get cannot assign to function call. Is there a way to to this ?

Philip Z.
  • 206
  • 2
  • 6

1 Answers1

0

You can access and modify the underlying array using df.values.

let json = [{
    fruit: "peach",
    rating: 10,
}, {
    fruit: "blueberry",
    rating: 9,
}];

let df = new danfo.DataFrame(json);
df.print();
╔════════════╤═══════════════════╤═══════════════════╗
║            │ fruit             │ rating            ║
╟────────────┼───────────────────┼───────────────────╢
║ 0          │ peach             │ 10                ║
╟────────────┼───────────────────┼───────────────────╢
║ 1          │ blueberry         │ 9                 ║
╚════════════╧═══════════════════╧═══════════════════╝
df.values[0][1] = 9000; // modify row 0, col 1 (rating)
df.print();
╔════════════╤═══════════════════╤═══════════════════╗
║            │ fruit             │ rating            ║
╟────────────┼───────────────────┼───────────────────╢
║ 0          │ peach             │ 9000              ║
╟────────────┼───────────────────┼───────────────────╢
║ 1          │ blueberry         │ 9                 ║
╚════════════╧═══════════════════╧═══════════════════╝

TypeScript will complain at the array indexing but as any will suppress it.

((df.values[0] as any)[1] as any) = 9000;
rkuang25
  • 79
  • 7