This error occurs when you try to access the 'values' attribute of a NumPy array. The 'values' attribute is not a valid attribute for a NumPy array.

NumPy arrays are different from pandas DataFrames or Series, which have a 'values' attribute that returns the underlying data as a NumPy array. In NumPy, you can access the data directly using the array indexing syntax, like this:

import numpy as np

a = np.array([1, 2, 3])
print(a[0])  # returns 1

If you are trying to convert a NumPy array to a pandas DataFrame or Series, you can use the 'pd.DataFrame' or 'pd.Series' constructor:

import pandas as pd
import numpy as np

a = np.array([1, 2, 3])
df = pd.DataFrame(a, columns=['my_column_name'])
print(df)

Output:

   my_column_name
0               1
1               2
2               3
'numpy.ndarray' object has no attribute 'values' - Error Explanation and Solution

原文地址: https://www.cveoy.top/t/topic/nH55 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录