I have a column which is in datetime format and I want to change it to be date format.
db['Date'] = db['Date'].apply(lambda x: x.date())
And then I got a warning:
__main__:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_index,col_indexer] = value instead
I did some search and changed it to be:
db.loc[:,'Date'] = db.loc[:,'Date'].apply(lambda x: x.date())
The error message is:
if isnull(other) or (np.isscalar(other) and other == tslib.iNaT):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
This error also happens when I tried to assign new values to a series:
db['new'] = db.apply(lambda x: my_func(x['A'],x['B']))
Could anyone suggest what is happening here and how can I get rid of the warnings?
I noticed that I can turn the warning off by setting db.is_copy = False
but I'd rather keep it there in case I indeed have important errors. So I still hope to do something to make the code running adequately without warning messages.
Thanks in advance.