I am always getting a warning from python at following scenario: I have a list with a length smaller then the dataframe I created as a copy of another dataframe column and I want to add it to that new dataframe as a new column with an known offset so the list ends with the last dataframe entry.
data = data["ColumnName"].copy()
data["NewColumn"] = float("NaN")
data.iloc[offset:]["NewColumn"] = list
This gives me the error:
SettingWithCopyWarning: 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
When I do the same with .loc:
data.loc[offset:,"NewColumn"] = list
I am getting following warning:
FutureWarning: Slicing a positional slice with .loc is not supported, and will raise TypeError in a future version. Use .loc with labels or .iloc with positions instead.
Can anyone help me understanding the problem and show how to fix the warning?