pandas 获取在其他对象中定义的 Dataframe 时出错,即TypeError:“DataFrame”对象不可调用

3mpgtkmj  于 2022-12-09  发布在  其他
关注(0)|答案(1)|浏览(231)

我是新的python和试图创建一些代码为我的理解。我得到错误的获取tick_data在另一个对象。
下面是我的代码,其中我定义了 Dataframe

class MarketDataLoader():
    
    def __init__(self,symbols,cashPerTrade,broker_config: 'BrokerConfig'):
      self._tick_data = None
      #few other init var

   @property
   def tick_data(self) -> 'pandas.DataFrame':
        return self._tick_data
    
    def process_tick_data(self, data, dataframe):
        # some processing for tick data and assign value to tick data
   
    def process_and_resample_tick_data(self):
        self._api.subscribe_market_data(self._symbols, (self.process_tick_data,))

当调用process_and_resample_tick_data方法时,它开始流到process_tick_data方法
那么在交易执行者阶层

class TradeExecutor():

    def __init__(self,market_data: 'MarketDataLoader',trade_config:'TradeConfig',broker_config:'BrokerConfig'):
        print("Init Trade execute")
        self._market_data = market_data
        self._trade_config = trade_config
        self._broker_config =broker_config

    def start_trade(self):
        logger.info("starting trade from Trade Executor for ",self._trade_config.symbols,
                    " cash for trade ",self._trade_config.cash_per_trade)
        while True:  # repeat until we get all historical bars
            time.sleep(10)
            print("trade time ",self._market_data)
#error on following line of code
            tick_frame = self._market_data.tick_data()

我在tick_frame = self._market_data.tick_data()上遇到错误我不确定如何解决以下错误

tick_frame = self._market_data.tick_data()
TypeError: 'DataFrame' object is not callable
python-BaseException
2izufjch

2izufjch1#

您尝试呼叫宣告为属性的方法。
当我们使用@property装饰器时,我们把方法当作一个属性。

class JBug(object):
    def __init__(self):
        name = 'Junie'

    @property
    def hello(self):
        return "Hello, my name is %s" % name

为了获得所需的行为,我们不调用hello,而是将其视为一个属性:

>>> J = JBug()
>>> print(J.hello)
Hello, my name is Junie

相关问题