Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (120 points)

i was running this code :

data = pd.DataFrame(index=np.arange(0, total_images), columns=["patient_id", "path", "target"])

k = 0

for n in range(len(folder)):

    patient_id = folder[n]

    patient_path = base_path +"/"+ patient_id 

    for c in [0,1]:

        class_path = patient_path + "/" + str(c) + "/"

        subfiles = listdir(class_path)

        for m in range(len(subfiles)):

            image_path = subfiles[m]

            data.iloc[k]["path"] = class_path + "/" +image_path

            data.iloc[k]["target"] = c

            data.iloc[k]["patient_id"] = patient_id

            k += 1  

data.head(100)

and am getting this error 

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-35-01bd49c11992> in <module>
     10         for m in range(len(subfiles)):
     11             image_path = subfiles[m]
---> 12             data.iloc[k]["path"] = class_path + "/" +image_path
     13             data.iloc[k]["target"] = c
     14             data.iloc[k]["patient_id"] = patient_id

~\Miniconda3\envs\tensorflow\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
   1422 
   1423             maybe_callable = com.apply_if_callable(key, self.obj)
-> 1424             return self._getitem_axis(maybe_callable, axis=axis)
   1425 
   1426     def _is_scalar_access(self, key: Tuple):

~\Miniconda3\envs\tensorflow\lib\site-packages\pandas\core\indexing.py in _getitem_axis(self, key, axis)
   2155 
   2156             # validate the location
-> 2157             self._validate_integer(key, axis)
   2158 
   2159             return self._get_loc(key, axis=axis)

~\Miniconda3\envs\tensorflow\lib\site-packages\pandas\core\indexing.py in _validate_integer(self, key, axis)
   2086         len_axis = len(self.obj._get_axis(axis))
   2087         if key >= len_axis or key < -len_axis:
-> 2088             raise IndexError("single positional indexer is out-of-bounds")
   2089 
   2090     def _getitem_tuple(self, tup):

IndexError: single positional indexer is out-of-bounds
can anyone help me please ?

Please log in or register to answer this question.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...