简体   繁体   English

如何通过在 for 循环中更新其列值来更新数据集?

[英]How to update dataset through updating its column values in a for loop?

I want to loop over a list of columns and if a certain condition is satisfied then i want to change the value of the current column with NaN , but with what i have tried (below) i override with previous dataset instead of updating the last dataset satisfying the condition:我想遍历列列表,如果满足某个条件,那么我想用NaN更改当前列的值,但是我尝试过(下面)我用以前的数据集覆盖而不是更新最后一个数据集满足条件:

for (String att: listAtts) {
           datasetInit = ...
            resDf = datasetInit;
            if (condition) {
                resDf = resDf.withColumn(att,lit("NaN"));
...

My problem here is that for each iteration resDf takes datasetInit which erase the last resDf update.我的问题是,对于每次迭代resDf都会使用datasetInit来擦除最后一次resDf更新。 How to achieve that in JAVA?如何在 JAVA 中实现?

Thanks谢谢

I solved it using the following:我使用以下方法解决了它:

...
if (resDf.count == 0)
  resDf = datasetInit;
...

To Not assign the datasetInit if resDf has at least been updated once如果resDf至少更新过一次,则不分配datasetInit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM