AttributeError: 'DataFrame' object has no attribute 'reshape'
时间: 2023-09-26 19:06:59 浏览: 35
`reshape` is a method of Numpy arrays and is not directly available in Pandas DataFrames. If you want to reshape a DataFrame, you can first convert it to a Numpy array using the `values` attribute, and then use the `reshape` method:
```python
import pandas as pd
# create a DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
# convert to a Numpy array and reshape
arr = df.values.reshape((3, 3))
```
Alternatively, you can use the `stack` method to reshape the DataFrame into a Series, and then use the `values` attribute to convert it to a Numpy array:
```python
# stack the DataFrame and convert to a Numpy array
arr = df.stack().values.reshape((3, 3))
```
Note that the shape of the reshaped array should match the number of elements in the original DataFrame.