Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading