Performance increases by replacing "df.loc" by "df.at"

This commit is contained in:
dario
2023-12-18 00:13:22 +01:00
parent f5f30953ca
commit 58d362c8f9
8 changed files with 11 additions and 13 deletions

View File

@@ -49,9 +49,9 @@ class Logger(Advanceable):
self.__idx = -1
def _on_step(self, _: float):
self.__df = pd.concat([self.__df, pd.DataFrame()], ignore_index=True)
self.__df = pd.concat([pd.DataFrame(), self.__df], ignore_index=True, copy=False)
self.__idx += 1
self.__df.loc[self.__idx, 'time'] = self.get_time()
self.__df.at[self.__idx, 'time'] = self.get_time()
def _on_reset(self):
self.__df = pd.DataFrame.from_dict({'time': [self.get_time()]}).astype(np.float64)
@@ -64,12 +64,12 @@ class Logger(Advanceable):
value (Any): The value to log.
domain (str, optional): The domain the value belongs to. Defaults to 'any'.
"""
name = domain + '/' + attrib
name = f'{domain}/{attrib}'
if name not in self.__df.columns:
self.__df[name] = pd.Series([pd.NA] * len(self.__df))
self.__df.loc[self.__idx, name] = value
self.__df.at[self.__idx, name] = value
def get_dataframe(self) -> pd.DataFrame:
return self.__df