How to iterate over a danfojs DataFrame
Asked Answered
K

1

7

Is it possible to iterate a danfojs DataFrame? Thought maybe could use the .iloc function with an index, but .iloc returns a DataFrame, not a Series.

Kotz answered 11/5, 2021 at 1:55 Comment(4)
What activity are you trying to do with each row - perhaps there's a better approach to do that instead of explicitly iterating over each rowDemount
iterrows() is a common pandas.DataFrame function in python, so I figured there would there would be an equivalent in danfoJS. I use it for accessing items on a row by row basis. The workaround is to iterate over indices and access the desired column values with the index, which is much more tedious if there are a lot of columns to look at.Kotz
I'm curious about this as well. Are we supposed to use .values or .toJSON() and just iterate those?Eldin
I'm wondering the same thing, I have no idea how to do that. I think the closest we have is apply but I would like a readonly approach.Inapplicable
G
1

you have to select the field column like you would do in pandas.

 async function main(){
  let df = await dfd.readExcel(__dirname + "/FormKeff.xlsx")

  for (let i = 0; i < df.shape[0]; i++) {
    let person = {};
    person.name = df.iloc({rows: [i]})["Nome"].values[0];
    person.email = df.iloc({rows: [i]})["Email"].values[0];
    person.phone = df.iloc({rows: [i]})["Telefone"].values[0];
    person.created_at = df.iloc({rows: [i]})["Data"].values[0];
  }

}

main();
Graticule answered 14/2, 2023 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.