0

I have seen this a million times, I am somehow chaining indexes and am getting a setting with copy warning. The code I am using is below:

toEmail['median'] = np.nanmedian(toEmail.filter(like = 'foo_'), axis = 1)

I am guessing that it has to do with filter is creating some slice but I am not sure. I have tried the following, neither of which worked.

toEmail['median'] = np.nanmedian(toEmail.filter(like = 'foo_').copy(deep=True), axis = 1)
toEmail['median'] = list(np.nanmedian(toEmail.filter(like = 'foo_'), axis = 1))

--- EDIT ---
Per the comments I got this dataframe from this:

toEmail = fullDf[['foo_1', 'foo_2', 'bar_1', 'bar_2']]

and adding the copy here fixes the issues

toEmail = fullDf[['foo_1', 'foo_2', 'bar_1', 'bar_2']].copy()
qwertylpc
  • 2,016
  • 7
  • 24
  • 34
  • It looks like problem is on the left hand side of the assignment. How was toEmail obtained? – matusko Mar 28 '18 at 17:36
  • @matusko updated thanks – qwertylpc Mar 28 '18 at 17:39
  • [relevant question](https://stackoverflow.com/questions/38835483/confusion-re-pandas-copy-of-slice-of-dataframe-warning?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Floydian Mar 28 '18 at 18:24

0 Answers0