AttributeError: 'numpy.ndarray' object has no attribute 'columns'
时间: 2023-09-21 22:06:56 浏览: 83
python的mysql数据查询及报错AttributeError: ‘Connection’ object has no attribute ‘curson’
This error occurs because the `numpy.ndarray` object doesn't have a `columns` attribute. The `columns` attribute belongs to a Pandas DataFrame object.
To solve this error, you can convert the `numpy.ndarray` object to a Pandas DataFrame object using the `pandas.DataFrame()` function. Then, you can access the `columns` attribute.
Example:
```
import pandas as pd
import numpy as np
# create a numpy array
arr = np.array([[1, 2, 3], [4, 5, 6]])
# convert the numpy array to a pandas DataFrame
df = pd.DataFrame(arr)
# access the columns attribute
print(df.columns)
```
Output:
```
RangeIndex(start=0, stop=3, step=1)
```
阅读全文