AI4Finance-Foundation / FinRL-Meta

FinRL­-Meta: Dynamic datasets and market environments for FinRL.
https://ai4finance.org
MIT License
1.17k stars 556 forks source link

China_A_share_market_tushare AttributeError #283

Open zhilee2023 opened 1 year ago

zhilee2023 commented 1 year ago

When I run China_A_share_market_tushare.ipynb, the following error came accross. It seems the dataframe has no attribute date.


AttributeError Traceback (most recent call last) Cell In[42], line 3 1 env_kwargs = { "stock_dim": stock_dimension, "hmax": 1000, "initial_amount": 1000000, "buy_cost_pct": 6.87e-5, "sell_cost_pct": 1.0687e-3, "reward_scaling": 1e-4, "state_space": state_space, "action_space": stock_dimension, "tech_indicator_list": config.INDICATORS, "print_verbosity": 1, "initial_buy": True, "hundred_each_trade": True } ----> 3 e_train_gym = StockTradingEnv(df=train, **env_kwargs)

File F:\FinRL-Tutorials\1-Introduction\meta\env_stock_trading\env_stocktrading_China_A_shares.py:82, in StockTradingEnv.init(self, df, stock_dim, hmax, initial_amount, buy_cost_pct, sell_cost_pct, reward_scaling, state_space, action_space, tech_indicator_list, turbulence_threshold, make_plots, print_verbosity, day, initial, previous_state, model_name, mode, iteration, initial_buy, hundred_each_trade) 80 self.rewards_memory = [] 81 self.actions_memory = [] ---> 82 self.date_memory = [self._get_date()] 83 self._seed()

File F:\FinRL-Tutorials\1-Introduction\meta\env_stock_trading\env_stocktrading_China_A_shares.py:451, in StockTradingEnv._get_date(self) 449 def _get_date(self): 450 if len(self.df.tic.unique()) > 1: --> 451 date = self.data.date.unique()[0] 452 else: 453 date = self.data.date

File D:\Anaconda\envs\stock\lib\site-packages\pandas\core\generic.py:5902, in NDFrame.getattr(self, name) 5895 if ( 5896 name not in self._internal_names_set 5897 and name not in self._metadata 5898 and name not in self._accessors 5899 and self._info_axis._can_hold_identifiers_and_holds_name(name) 5900 ): 5901 return self[name] -> 5902 return object.getattribute(self, name)

AttributeError: 'DataFrame' object has no attribute 'date'

chalengr commented 1 year ago

I want to ask this question too, do you find the answer?

zhilee2023 commented 1 year ago

I changed the codes to df['time'] or df['date']. It works for me.

On Thu, Apr 20, 2023 at 10:50 AM chalengr @.***> wrote:

I want to ask this question too, do you find the answer?

— Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_AI4Finance-2DFoundation_FinRL-2DMeta_issues_283-23issuecomment-2D1515636733&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=iIWsBpN06F9GttDzigzIfA&m=Fxn7nzAWLHkcjo8mgaccuIZoASCXFEZx1ORUFxMQ5OT3w2vwoVgdlSYEqguAH8WU&s=Wr12awWbEeWZ83vHyBDPhcXI4sRMkooHKVQNZb_7bdU&e=, or unsubscribe https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_A6ATO3QZYIILMRXLAYURNUDXCCP77ANCNFSM6AAAAAAWKQYWMA&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=iIWsBpN06F9GttDzigzIfA&m=Fxn7nzAWLHkcjo8mgaccuIZoASCXFEZx1ORUFxMQ5OT3w2vwoVgdlSYEqguAH8WU&s=bRCe5WLK0kfL617ZMUAHEXhdTZM69ZOExl7b4L9cccY&e= . You are receiving this because you authored the thread.Message ID: @.***>

chalengr commented 1 year ago

Could you please send me the changed code , my email is 1544123230@qq.com, thank you.

huijian222 commented 1 year ago

just rename the col name works train = train.rename(columns={'time': 'date'})