0

I have the following database:

                    time    open    high     low   close
0    2021-07-29 21:12:18  131.50  131.51  131.45  131.45
1    2021-07-29 21:14:49  131.40  131.50  131.40  131.41
2    2021-07-29 21:20:56  131.62  131.62  131.62  131.62
3    2021-07-29 21:20:56  131.41  131.50  131.40  131.40
4    2021-07-29 21:22:28  131.36  131.40  131.31  131.40
..                   ...     ...     ...     ...     ...
259  2021-07-30 09:05:26  130.19  130.26  130.16  130.17
260  2021-07-30 09:07:16  130.15  130.20  130.10  130.20
261  2021-07-30 09:08:10  130.21  130.29  130.19  130.29
262  2021-07-30 09:09:10  130.30  130.37  130.27  130.37
263  2021-07-30 09:09:56  130.38  130.40  130.30  130.30

[264 rows x 5 columns]

This code successfully prints the varible 'time' to a csv file:

import pandas

row = [0]
range_interval = [10]

def strategy_tester():
  dataframe = pandas.read_csv('file.csv')
  while row[-1] < len(dataframe.index):
    time = dataframe.iloc[row[-1], 0]
    # open = dataframe.iloc[row[-1], 1]

    print(time, file = open('txt.txt', 'a'))
    row.append(row[-1] + 1)

while range_interval[-1] < 11:
  strategy_tester()

  range_interval.append(range[-1] + 1)

However, when I don't comment out open = dataframe.iloc[row[-1], 1] I get 'numpy.float64' object is not callable. I also find it confusing that when I print 'time' to the terminal (e.g. print(time)) and I don't comment out open = dataframe.iloc[row[-1], 1] the code works fine without errors.

Any idea as to why this error is occurring?

2 Answers2

3

Any idea as to why this error is occurring?

You are overshadowing open builtin, consider that

open = dataframe.iloc[row[-1], 1]
print(time, file = open('txt.txt', 'a'))

is equivalent to

print(time, file = dataframe.iloc[row[-1], 1]('txt.txt', 'a'))

In python if possible you should avoid overshadowing builtins. In case you do not know if some name is already used for builtin in python version you are using consult print(dir(__builtins__)) output.

Daweo
  • 31,313
  • 3
  • 12
  • 25
0

Not callable means the object you are trying to access the method with doesn't implement it, for more details read here.