MorvanZhou / Reinforcement-learning-with-tensorflow

Simple Reinforcement learning tutorials, 莫烦Python 中文AI教学
https://mofanpy.com/tutorials/machine-learning/reinforcement-learning/
MIT License
8.83k stars 5k forks source link

pandas==1.4.4 FutureWarning解决:关于'df.append' use 'pandas.concat' instead. #209

Open TysonSir opened 1 year ago

TysonSir commented 1 year ago

pandas==1.4.4 FutureWarning解决

警告内容

Reinforcement-learning-with-tensorflow\contents\2_Q_Learning_maze\RL_brain.py:45: 
FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. 
Use pandas.concat instead.
  self.q_table = self.q_table.append(

原代码

    def check_state_exist(self, state):
        if state not in self.q_table.index:
            # append new state to q table
            self.q_table = self.q_table.append(
                pd.Series(
                    [0]*len(self.actions),
                    index=self.q_table.columns,
                    name=state,
                )
            )

新代码

    def check_state_exist(self, state):
        if state not in self.q_table.index:
            # append new state to q table
            self.q_table = pd.concat([self.q_table,
                pd.Series(
                    [0]*len(self.actions),
                    index=self.q_table.columns,
                    name=state,
                ).to_frame().T
            ])
L1zw commented 10 months ago

thanks a lot

ShuiYidi commented 5 months ago

I use this code instead

def check_state_exist(self, state):
        if state not in self.q_table.index:
            # append new state to q table
            new_state = pd.DataFrame(
                [[0*i for i in range(len(self.actions))]],
                columns=self.q_table.columns,
                index=[state],
            )
            self.q_table = pd.concat([self.q_table, new_state], ignore_index=False)