0

The line

res2.loc[: , other_column_name] = res2.loc[: , other_column_name].apply(np.log) 

,where res2 is a pandas.DataFrame, gives the following warning:

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

After several attempts, I have been able to get rid of the warning by rewriting the line into this

res3 = res2.copy()
log = res2.loc[: , other_column_name].apply(np.log) 
res3.loc[: , other_column_name] = log

This is clearly not an elegant solution, is there any better way to solve this?

EDIT 1

res2 was created this way:

res2 = res1[res1.index <= last_valid_sentiment]

also

res2.head()

        sentiment  inf_neg
2001-11-28  -2.856371      0.534482
2001-12-26  -2.023266      0.473392
2002-01-30  -1.505361      0.444845
2002-02-27  -2.121079      0.433922
2002-03-27  -1.692547      0.469621
user3889486
  • 656
  • 1
  • 7
  • 21
  • 1
    Ignore the warning/turn it off? It's well-known that it throws false positives. I'm not convinced that `res2.loc[: , other_column_name].apply(np.log) ` is an issue, but you could take the `values` to be sure – roganjosh Oct 01 '18 at 20:42
  • it all depends on how you construct res2, can you show us the code? – Yuca Oct 01 '18 at 20:42
  • Actually, I'm confused. `res2[column_name] = np.log(res2[column_name])`? – roganjosh Oct 01 '18 at 20:48

0 Answers0