this error apeared to me,how to slove it?

/tmp/sessions/1ef88683057226d0/main.py:27: UserWarning: Pandas doesn’t allow columns to be created via a new attribute name – see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access Colour_Features.Columns=[“Feature 1″,”Feature 2″,”Colour”]

import pandas as pd 

red_values = pd.DataFrame([[255,0,20],[210,30,0],[220,40,5],[240,10,30], 
[225,60,20]])
green_values = pd.DataFrame([[0,255,0],[10,240,5],[0,240,20],[5,220,30], 
[30,230,10]])
blue_values = pd.DataFrame([[30,10,220],[10,10,255],[0,0,240],[25,15,210], 
[0,20,220]])

red_values.columns =["R","G","B"]
green_values.columns =["R","G","B"]
blue_values.columns =["R","G","B"]

print(red_values)
print(green_values)
print(blue_values)


Feature1 = red_values.loc[:,"R"]-red_values.loc[:,"G"]
Feature2 = 2*red_values.loc[:,"B"] - red_values.loc [:,"R"] - 
red_values.loc [:,"G"]

print(Feature1)
print(Feature2)

Colour_Features=pd.concat([Feature1, Feature2], axis=1)


Colour_Features[2]=["red","red","red","red","red"]

Colour_Features.Columns=["Feature 1","Feature 2","Colour"]

print(Colour_Features)

Answer

The Columns here shouldn’t be capitalized. That’s where the warning is coming from:

Change this:

Colour_Features.Columns=["Feature 1","Feature 2","Colour"]

To:

Colour_Features.columns=["Feature 1","Feature 2","Colour"]

Leave a Reply

Your email address will not be published. Required fields are marked *