The problem lies in the following line:
df = StandardScaler().fit_transform(df)
It returns a numpy array (see docs), which does not have a drop function.
You would have to convert it into a pd.DataFrame first!
new_df = pd.DataFrame(StandardScaler().fit_transform(df), columns=df.columns, index=df.index)
Answer from tobsecret on Stack OverflowHi,
I'm trying to create a numpy v-stack and creating 3 np.array's for it, by filling them with a loop:
I get the error: 'AttributeError: 'numpy.ndarray' object has no attribute 'np' . I think I'm using the wrong notation to append to the empty arrays:
neighbor_id = [id_ for id_ in range(1, n_obs) if id_ != user_id]
neighbor_id_arr = np.array(neighbor_id)
similarity = np.array([])
num_interactions = np.array([])
# get similarity and num_interactions
for id_ in neighbor_id:
similarity.np.append(np.dot(user_item.loc[user_id],user_item.loc[id_])) #The issue is here, I think
num_interactions.np.append(user_interactions.loc[id_])
c = numpy.vstack((neighbor_id_arr, similarity,num_interactions))
Thanks!
James
python - 'numpy.ndarray' object has no attribute 'drop' - Stack Overflow
scikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Data Science Stack Exchange
Medical Data Visualizer Project Image Is Good but Errors Encountered
AttributeError: 'numpy.ndarray' object has no attribute 'numpy'
Videos
Because you extracted the values of your Pandas dataframe, your data have been converted into a NumPy array and thus the column names have been removed. The time column is the first column of your data, so all you really need to do is index into it so that you extract the second column and onwards:
x_time_train = x_train[:, 0]
x_train = x_train[:, 1:]
x_time_test = x_test[:, 0]
x_test = x_test[:, 1:]
Take note that I've separated the time values for both training and testing datasets as you require them for plotting.
X_train is an array not a dataframe You need to know the position of the column to drop
np.delete(X_train, [index_to_drop], 1)
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]
The solution:
The given dataset was already an array, so I didn’t need to call .values.
The problem lies in the following line:
df = StandardScaler().fit_transform(df)
It returns a NumPy array (see the documentation), which does not have a drop function. You would have to convert it into a pd.DataFrame first!
new_df = pd.DataFrame(StandardScaler().fit_transform(df), columns=df.columns, index=df.index)
Hello there.
I started doing manim a few weeks ago and, since there's no official documentation, I've been trying to replicate some of the scenes of 3b1b's old proyects. Specifically, I'm trying to replicate this animation ( https://www.youtube.com/watch?v=k7RM-ot2NWY at 0:37), but whenever I try to render the file, this error appears: "AttributeError: 'numpy.ndarray' object has no attribute 'move_to'".
I've already spend hours looking through the manimlib files but i can't make sense out of this.
Heres the code of the animation that I've got so far:
from manimlib.imports import *
class VectoresComoEscalares(VectorScene):
CONFIG = {
"axis_config": {
"stroke_color": WHITE,
"stroke_width": 2,
"stroke_opacity": 0.8,
},
"background_line_style": {"stroke_width": 2, "stroke_opacity": 0.5,},
"vcoords": ([3, 2]),
"vcolor": ORANGE,
}
def construct(self):
grid = NumberPlane(**self.CONFIG)
self.add(grid)
self.lock_in_faded_grid()
self.play(ShowCreation(grid), run_time=2)
self.wait()
kwargs = {
"stroke_width": 4,
}
vector = self.add_vector(self.vcoords, self.vcolor, **kwargs)
array, x_line, y_line = self.vector_to_coords(vector)
self.add(array)
self.wait()
new_array = self.ideas_generales_escalares(array, vector)
self.scale_basis_vectors(new_array)
self.show_symbolic_sum(new_array, vector)
def ideas_generales_escalares(self, array, vector):
startmo = self.get_mobjects()
txt = TextMobject(
"Vean cada coordenada como un escalar.", tex_to_color_map={"escalar": RED}
)
txt.to_edge(DOWN)
x, y = array.get_entries()
new_x = x.copy().scale(2).set_color(X_COLOR)
new_x.move_to(3 * LEFT + 2 * UP)
new_y = y.copy().scale(2).set_color(Y_COLOR)
new_y.move_to(3 * RIGHT + 2 * UP)
i_hat, j_hat = self.get_basis_vectors()
new_i_hat = Vector(self.vcoords[0] * i_hat.get_end(), color=X_COLOR)
new_j_hat = Vector(self.vcoords[1] * j_hat.get_end(), color=X_COLOR)
g1 = VGroup(i_hat, new_i_hat).shift(3 * LEFT)
g2 = VGroup(i_hat, new_j_hat).shift(3 * RIGHT)
new_array = Matrix([new_x.copy(), new_y.copy()])
new_array.scale(0.5)
new_array.shift(
-new_array.get_boundary_point(-vector.get_end()) + 1.1 * vector.get_end()
)
self.remove(*startmo)
self.play(Transform(x, new_x), Transform(y, new_y), Write(txt))
self.play(FadeIn(i_hat), FadeIn(j_hat))
self.wait()
self.play(FadeIn(i_hat), FadeIn(j_hat))
self.wait()
self.play(Transform(i_hat, new_i_hat), Transform(j_hat, new_j_hat), run_time=3)
self.wait()
startmo.remove(array)
new_x, new_y = new_array.get_entries()
self.play(
Transform(x, new_x),
Transform(y, new_y),
FadeOut(i_hat),
FadeOut(j_hat),
Write(new_array.get_brackets()),
FadeIn(VMobject(*startmo)),
FadeOut(txt),
)
self.remove(x, y)
self.add(new_array)
return new_array
Using .values on a pandas dataframe gives you a numpy array. This will not contain column names and such. You do this when setting X like this:
X = dataset[['Read?', 'x1', .. ,'x47']].values
But then you try to get the column names from X (which it does not have) by writing X.columns here:
coeff_df = pd.DataFrame(regressor.coef_, X.columns, columns=['Coefficient'])
So store your column names in a variable or input them again, like this:
coeff_df = pd.DataFrame(regressor.coef_, ['Read?', 'x1', .. ,'x47'], columns=['Coefficient'])
hi remove values method
X = dataset[['Read?', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6' , 'x7','x8','x9','x10','x11','x12','x13','x14','x15','x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31','x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47']]
coeff_df = pd.DataFrame(regressor.coef_, X.columns, columns=['Coefficient'])
I think I've figured it out.
The .remove() method is a list method, not an ndarray method.
So by using array.tolist() I can then apply the .remove() method and get the required result.
This does not directly address your question, as worded, but instead condenses some of the points made in the other answers/comments.
The following demonstrates how to, effectively, remove the value 0.0 from a NumPy array.
>>> import numpy as np
>>> arr = np.array([0.1, 0.2, 0.0, 1.0, 0.0]) # NOTE: Works if more than one value == 0.0
>>> arr
array([0.1, 0.2, 0. , 1. , 0. ])
>>> indices = np.where(arr==0.0)
>>> arr = np.delete(arr, indices)
>>> arr
array([0.1, 0.2, 1. ])
Another useful method is numpy.unique(), which, "Returns the sorted unique elements of an array.":
>>> import numpy as np
>>> arr = np.array([0.1, 0.2, 0.0, 1.0, 0.0])
>>> arr = np.unique(arr)
>>> arr
array([0. , 0.1, 0.2, 1. ])