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

@@ -199,18 +199,18 @@ class Dataset(Advanceable):
float: Returns the requested value.
"""
if self.__interpolation == 'linear':
t_min = self.__df['time'].iloc[self.__idx]
t_max = self.__df['time'].iloc[self.__idx + 1]
t_min = self.__df.at[self.__idx, 'time']
t_max = self.__df.at[self.__idx + 1, 'time']
# Sometimes no time passes in-between two samples.
if t_max == t_min:
return self.__df[name].iloc[self.__idx]
return self.__df.at[name, self.__idx]
# Compute the weight for interpolation.
alpha = (self.get_time() - t_min) / (t_max - t_min)
# Interpolate linearly between the two data points.
return (1 - alpha) * self.__df[name].iloc[self.__idx] + alpha * self.__df[name].iloc[self.__idx + 1]
return (1 - alpha) * self.__df.at[self.__idx, name] + alpha * self.__df.at[self.__idx + 1, name]
def fetch_values(self, names: List[str]) -> np.array:
"""Get specific values from the dataframe.