From a904aaa252623c17e2cbb5b710b1baed2466f5ee Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:56:16 +0300 Subject: [PATCH] Fix pandas warnings --- src/stravavis/plot_dumbbell.py | 6 +----- src/stravavis/plot_landscape.py | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/stravavis/plot_dumbbell.py b/src/stravavis/plot_dumbbell.py index 65a7388..54670b0 100644 --- a/src/stravavis/plot_dumbbell.py +++ b/src/stravavis/plot_dumbbell.py @@ -40,11 +40,7 @@ def plot_dumbbell( # Get activity start and end times activities["start"] = activities["Activity Date"] - activities["duration"] = 0 - for i in range(len(activities)): - activities["duration"][i] = pd.Timedelta( - activities["Elapsed Time"][i], unit="s" - ) + activities["duration"] = pd.to_timedelta(activities["Elapsed Time"], unit="s") activities["end"] = pd.to_datetime(activities["start"] + activities["duration"]) # Remove activities outside the year_min -> year_max window diff --git a/src/stravavis/plot_landscape.py b/src/stravavis/plot_landscape.py index eb386c5..2c2caf2 100644 --- a/src/stravavis/plot_landscape.py +++ b/src/stravavis/plot_landscape.py @@ -19,8 +19,8 @@ def plot_landscape(df, output_file="landscape.png"): processed = [] for activity in track(activities, "Processing tracks"): - df_i = df[df["name"] == activity] - df_i["dist_norm"] = (df_i["dist"] - df_i["dist"].min()) / ( + df_i = df[df["name"] == activity].copy() + df_i.loc[:, "dist_norm"] = (df_i["dist"] - df_i["dist"].min()) / ( df_i["dist"].max() - df_i["dist"].min() ) processed.append(df_i)