数据框在作为参数传递时失去调用方法的能力

huangapple go评论70阅读模式
英文:

Data frame losing ability to call method when passed as an argument

问题

在我正在处理的脚本中,我有一个数据框变量,我将其作为参数传递给另一个方法。之前在原始方法中,如果我调用data_frame.loc[x],它会顺利运行,但是现在在下一个方法中,通过data_frame传递进来后,它不再识别这个方法。

错误信息为:

对象没有属性'loc'

尝试使用.loc方法,但出现了错误。

英文:

In a script I'm working on, I have a data frame variable I am passing as an argument to another method. Previously in this original method, if I were to call data_frame.loc[x] it would work without issue, however now in the next method with data_frame passed through, it does not recognize this method.

def _validate_result_for_attribute(self, result_file, test_summary):
    
    data_frame = GazeTest.get_data_frame_from_csv(result_file) 

    for i in range(len(data_frame)):
        if not (self._validate_eyes_available(data_frame)):
            data_frame = data_frame.drop([i]) 
  
    self._update_test_case_fields(data_frame, result_file, test_summary)
    
    
def _validate_eyes_available(data_frame, index):
    # Checking if the each eye is available
    if (data_frame.loc[index, RIGHT_EYE_STATUS] == 1 and
        data_frame.loc[index, LEFT_EYE_STATUS] == 1):  
        return True
    else:
        return False

Error reads;

object has no attribute 'loc'

Tried to use .loc method but was given an error.

答案1

得分: 0

我看到你的代码有一个问题:当你调用_validate_eyes_available(data_frame)时,你没有传递索引。这可能会导致在这个data_frame.loc[index, RIGHT_EYE_STATUS]中出现错误,因为你在使用索引时没有传递它。

关于loc属性错误,你需要确保data_frame变量实际上是一个数据框架。只需打印它并在传递之前确保它
print(type(data_frame))

英文:

I see an issue in your code: when you call _validate_eyes_available(data_frame) You didn't pass the index. this might cause an error for you in this data_frame.loc[index, RIGHT_EYE_STATUS] since you using index and you didn't pass it.

regarding the loc attribute error, you need to make sure that data_frame variable is actually dataframe. just print it and make sure before passing it
print(type(data_frame))

huangapple
  • 本文由 发表于 2023年7月13日 19:19:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定