5

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.

index49
  • 51
  • 1
  • 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 row – callmekatootie May 17 '21 at 15:30
  • 1
    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. – index49 May 19 '21 at 15:17
  • I'm curious about this as well. Are we supposed to use .values or .toJSON() and just iterate those? – chrismarx Jan 23 '22 at 18:09
  • I'm wondering the same thing, I have no idea how to do that. I think the closest we have is [apply](https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.apply) but I would like a readonly approach. – Telokis Dec 17 '22 at 16:47

1 Answers1

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();