遍历数据帧行,并将每个迭代的输出保存在数据帧中

时间:2019-04-17 23:43:30

标签: python loops dataframe

我正在对我的语料库中的单词列表进行拼写更正。这花费了很长时间,而且我的连接中断了。为了防止这种情况,我想逐行处理语料库,并将输出保存在数据框中,然后每次将其导出。

我试图切片数据并导出输出,但是只有在所有行上进行迭代时,才导出输出

循环,这样即使连接中断代码也会运行

假设我的数据有100行,应该每10行输出一次

var data_obj_arr = [{"Size": "<1000", "Type": "Detached", "Location": "Northern", "Configuration": "Downflow", "Age": "Built Before 1980", "Collection_Name": "test"}, {"Size": "<1000", "Type": "Detached", "Location": "Northern", "Configuration": "Downflow", "Age": "Built Before 1980", "Collection_Name": "test"}, {"Size": "<1000", "Type": "Detached", "Location": "Northern", "Configuration": "Downflow", "Age": "Built Before 1980", "Collection_Name": "test"}]


function updateChosenOption(category_choice, category) {

  var arr = [];
  for (let i in data_obj_arr) {
    if (data_obj_arr[i][category] === category_choice) {
      arr.push(data_obj_arr[i]["Collection_Name"]);
    }
  }

  console.log(`Array: ${arr}`);
  //                                 v -- needs to be a regular funtion
  var results = data_obj_arr.filter(function(el) {
      return el[this.curr_category] === category_choice
    }, {curr_category: category}) // < -- to pass in this
    .map(el => el["Collection_Name"]);

  console.log(`Results: ${results}`);
}

updateChosenOption('Built Before 1980', 'Age')

0 个答案:

没有答案