I have a few dataframes, let's call them rates, sensors with "session_start", "value_timestamp" (timestamps) and "value" (float) columns. I want to add an "elapsed" column, which I've done successfully using the following code:
def add_elapsed_min(df):
  df["elapsed"] = (
    df["value_timestamp"] - df["session_start"].min()
  ).dt.total_seconds() / 60.0

for df in [rates, sensors]:
  add_elapsed_min(df)

Now, this code does work, and the elapsed column is correct. The minor problem is that I keep getting the SettingWithCopyWarning. I've tried changing the code as suggested by the warning, tried adding a contextlib.suppress, but can't seem to remove this warning. This makes me think I must be breaking some idiomatic way to do this. So I'm wondering: If you want to add a calculated column to many dataframes at once, how are you supposed to do this?

What's the idiomatic way to add a calculated column to multiple data frames?
Although I cannot create your warning in Pandas 1.5.3 and considering using .loc does not suppress the warning for you, one other option is to use df.insert instead.
def add_elapsed_min(df):
  elapsed = (df["value_timestamp"] - df["session_start"].min()) / 60.0
  df.insert(df.shape[1], 'elapsed', elapsed)

for df in [rates, sensors]:
  add_elapsed_min(df)

