DOC: added a reference to DataFrame assign in concatenate section of merging by obilodeau · Pull Request #18665 · pandas-dev/pandas (original) (raw)
I'm not sure I understand what you want, so let me tell you why I'm sending this PR.
I learned about assign
while trying to make a SettingWithCopyWarning warning go away. The proposed solution:
df.loc[:, ('derived_column')] = value * df.loc[:,('X0')]
was still generating a warning in my case. So I've read the doc about merging
and stumbled upon a pd.concat
solution:
df = pd.concat([df, value * df['X0']], axis=1) df.columns.values[1] = "derived_column"
Comparing notes with a colleague she told me about assign
and I found that solution more elegant:
df = df.assign(derived_column = value * df['X0'])
So that's why I want to add it to merging
. Now that I think about it, should I add a reference to assign
in the indexing-view-versus-copy doc also? I didn't do it because I don't understand why my original solution using .loc
still triggered the warning.
Back to your comment, I guess the when is when I want to add a column to a DataFrame but I already said that, no?