0

With regard to a data import on which I have to do simple operations, I encounter the following error with the iloc function. What can I do? Thanks

  List_of_X=pd.read_csv('List_of_X.csv')

   def main_function(self, i, j, test1, test2, test3, test4=None, test5=None, data_type=None):

       for x in range(0, len(self.List_of_X)):
   
           old_values_X = self.old_X()[i]
           new_values_X = self.List_of_X.iloc[x][1].astype('float')[j]

IndexError: invalid index to scalar variable (on new_values_X line)

I report the data sample:

name    | X | Y |
red     |1.5| 2 |
yellow  |5  | 3 |
blue    |3  | 4 |
9
  • 1
    What's self.old_X() function? Or is the main_function inside a class?
    – user17353495
    Commented Nov 22, 2021 at 15:01
  • self.old_X() is a function from another file to read the old values of the Xs. So, it is recalled inside a class. Thank you
    – wundolab
    Commented Nov 22, 2021 at 15:04
  • And what is i?
    – user17353495
    Commented Nov 22, 2021 at 15:05
  • 4
    you have not provided sample data but seems like List_of_X.iloc[x][1] is a scalar value and referencing index [j] to that value is inavlid
    – eshirvana
    Commented Nov 22, 2021 at 15:06
  • 1
    you have to provide sample data and a piece of code that we can reproduce the problem ,
    – eshirvana
    Commented Nov 22, 2021 at 15:21

1 Answer 1

1

The solution was to change the second declaration as:

       new_values_X = self.List_of_X.iloc[x][1].astype('float')

was not a value indexable

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.