this is my code.
(df = DataFrame Object)
[185] df = input_df.copy()
[186] df['date_time'] = df['date_time'].dt.date
[187] df['trade_status'][df['trade_status'] == 'DONE'] = 'FILLED'
this is my run window.
C:\Practice\Report\src\service\ReportService.py:187: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
How should I change the code 187 line?
Since the df is a copy from DataFram, do I need to modify any other code?
Help me, Please.
>Solution :
You can use numpy.where:
df['trade_status'] = np.where(df['trade_status']=='DONE', 'FILLED', df['trade_status'])
Edit:
Or you can use pandas.where:
df['trade_status'] = df['trade_status'].where(df['trade_status']!='DONE', 'FILLED')