[Solved]-attributeerror: 'numpy.ndarray' object has no attribute 'dropna'


AttributeError: 'numpy.ndarray' object has no attribute 'drop'

The error "AttributeError: 'numpy.ndarray' object has no attribute 'drop'" indicates that you're trying to use the `drop()` method, which is not available for NumPy arrays.

The `drop()` method is a method of Pandas DataFrame objects, not NumPy arrays. It is used to drop specified labels from rows or columns.

To resolve this error, you need to convert your NumPy array to a Pandas DataFrame if you intend to use the `drop()` method.

Here's how you can fix it:


import pandas as pd
import numpy as np

# Assuming you have a NumPy array 'arr'
arr = np.array([[1, 2, 3], [4, 5, 6]])

# Convert the NumPy array to a Pandas DataFrame
df = pd.DataFrame(arr)

# Now you can use the 'drop()' method on the DataFrame
# For example, to drop the first row:
new_df = df.drop(0)

# If you want to drop a column, you can specify the axis parameter:
# new_df = df.drop(0, axis=1)

# If you want to drop multiple rows or columns, you can pass a list of labels:
# new_df = df.drop([0, 1])
  

Since you've extracted the values of your Pandas dataframe, the data has been converted into a NumPy array, resulting in the removal of column names. Assuming the time column is the first column in your data, you can index into it to extract the second column onwards:


    x_time_train = x_train[:, 0]
    x_train = x_train[:, 1:]
    x_time_test = x_test[:, 0]
    x_test = x_test[:, 1:]