NaiveBae
NaiveBae

Reputation: 414

Setting with copy warning... what am I doing wrong?

I've read all kinds of documentation about this warning in Pandas. Aside from getting frustrated because I still haven't seen a case where it's not absolutely clear what is trying to be done (so the warning feels like a needless complication), I'm still getting the warning even when seemingly doing what is recommended.

Here is my original code. I'm trying to convert two columns ('A' and 'B') to DateTime.

df[['A', 'B']] = df[['A', 'B']].apply(pd.to_datetime)

After reading about using .loc as the preferred method, I changed to:

df.loc[:, ['A', 'B']] = df.loc[:, ['A', 'B']].apply(pd.to_datetime)

But I'm still getting the same warning. Would someone be kind enough to point out what I'm missing?

Upvotes: 0

Views: 515

Answers (0)

Related Questions