0

The line:

df["max_performance_factor_per_strat"] = df.groupby(["dsp_strategy_id"])[
    "performance_factor"
].transform(max)

is throwing the following warning:

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

How do I resolve this? What is causing it?

  • At some point _before_ this provided code you have unsafely subset your DataFrame. Either `new_df = df[cols]` or `new_df = df[mask]` when it should have been `new_df = df[cols].copy()` or `new_df = df[mask].copy()` The warning is letting you know that `df[mask]['col'] = value` may not work because `df[mask]` may produce a copy and recommends that you use `df.loc[mask, 'col'] = value` but that message is not clear here since you're doing something like `new_df = df[mask]` then later doing `new_df[col] = value` which looks to pandas like a (deferred) `df[mask][col] = value` call. – Henry Ecker Mar 03 '22 at 02:49

1 Answers1

0

As already discussed in

How to deal with SettingWithCopyWarning in Pandas

it's a false positive warning that can be safely disabled as follows:

import pandas as pd
pd.options.mode.chained_assignment = None

Hope this helped you out.

Kateryna
  • 36
  • 3