Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python, DataFrame Indexing Warning Problem

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading