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