python - Numpy.ndarray' object has no attribute 'loc' - Stack Overflow
scikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Data Science Stack Exchange
Python Coding help- keep recieving error message"AttributeError: 'numpy.ndarray' object has no attribute 'MESSAGE_A'"
Issue with head() on custom dtype
The problem is that train_test_split(X, y, ...) returns numpy arrays and not pandas dataframes. Numpy arrays have no attribute named columns
If you want to see what features SelectFromModel kept, you need to substitute X_train (which is a numpy.array) with X which is a pandas.DataFrame.
selected_feat= X.columns[(sel.get_support())]
This will return a list of the columns kept by the feature selector.
If you wanted to see how many features were kept you can just run this:
sel.get_support().sum() # by default this will count 'True' as 1 and 'False' as 0
because this :
X = df.iloc[:,:24481].values
y = df.iloc[:, -1].values
you should remove .values or make extra X_col, y_col like that
X_col = df.iloc[:,:24481]
y_col = df.iloc[:, -1]
https://imgur.com/gallery/yAdAjdx
Hello,
Linked is the screenshot of the two error messages I keep recieving as well as the code leading up to it. I'm trying to run an uplift on a classification tree. Any help is appreciated, I am still fairly new to python. Thank you!!
Write a function to calculate accumulated GPA (omit grade <5).
def gpa_of_pass(marks, credits):
gpa_list=[]
for i in range(len(marks)):
for j in range(len(marks[i])):
if marks[i][j] < 5:
marks=marks[i].pop(j)
for i in marks:
for j in i:
gpa_list.append(np.dot(i,credits)/sum(credits))
return gpa_list
marks = np.array([
[8.0, 9.0, 10.0],
[4.0, 9.0, 8.0],
[8.0, 3.0, 8.0],
[10.0, 9.0, 5.0],
[9.0, 9.0, 4.0]
])
credits = np.array([2, 2, 1])
gpa_of_pass(marks, credits)I ran a for loop to remove the grade <5 before calculating the GPA but I got the error in the title. Would you please have any suggestions? Thank you so much!
Recoding Variables
"
#I need to recode variables given there are "5" responses present on a 4-point scale
scldict = {1:1,2:2,3:3,4:4,5:'NaN'}
w1array = np.array(week1)
w1vec = w1array.vectorize(scldict)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-92-e3f6056d2727> in <module>()
2 scaldict = {1:1,2:2,3:3,4:4,5:'NaN'}
3 w1array = np.array(week1)
----> 4 w1vec = w1array.vectorize(scaldict)
AttributeError: 'numpy.ndarray' object has no attribute 'vectorize'Hello world, I am trying to recode variables given there are invalid responses in my survey data. I am using a dictionary and the vectorize function (seen on StackOverflow) to do this. Why is the vectorize function not available? I am lost.
Any help or suggestions for recoding variables in an efficient manner would be appreciated.