Please provide resolution this error. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please provide resolution this error.

import os import pandas as pd os.chdir("E:\data_sets") cars_data = pd.read_csv('Toyota.csv',index_col=0,na_values=["??","????"]) cars_data1 = cars_data.copy(deep=False) cars_data1.insert(10,"Price_Class","") i=0 while i < len(cars_data1['Price']): if(cars_data1['Price'][i] <= 8450): cars_data1['Price_Class'][i]="Low" elif(cars_data1['Price'][i] > 11950): cars_data1['Price_Class'][i]="High" else: cars_data1['Price_Class'][i]="Medium" i=i+1 cars_data1.columns Getting below error in the code: __main__:6: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy __main__:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy __main__:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

12th Apr 2020, 7:46 AM
Himanshu Jain
Himanshu Jain - avatar
2 Answers
0
I think you have to recheck the top one
13th Apr 2020, 4:09 PM
Basiiruwap
Basiiruwap - avatar
0
The first thing you should understand is that SettingWithCopyWarning is a warning, and not an error. The real problem behind the warning is that it is generally difficult to predict whether a view or a copy is returned. In most cases, the warning was raised because you have chained two indexing operations together. The SettingWithCopyWarning was created to flag "chained assignment" operations. This is made easier to spot because you might be used [] (square brackets) twice, but the same would be true if you used other access methods such as .loc[] , .iloc[] and so on. Moreover, you can change the behaviour of SettingWithCopyWarning warning using pd.options.mode.chained_assignment with three option "None/raise"/"warn". http://net-informations.com/ds/err/copy.htm
13th Apr 2021, 5:40 AM
stevejonn