'Series' object has no attribute 'reshape'?
时间: 2023-10-30 20:06:34 浏览: 48
The error message "'Series' object has no attribute 'reshape'" indicates that you are trying to use the `reshape` method on a pandas Series object, but it doesn't exist. The `reshape` method is available for numpy arrays, not pandas Series.
To reshape a pandas Series, you can convert it to a numpy array using the `values` attribute and then apply the reshape method. Here's an example:
```python
import pandas as pd
import numpy as np
# Create a sample Series
s = pd.Series([1, 2, 3, 4, 5])
# Convert the Series to a numpy array and reshape
arr = s.values.reshape((5, 1))
print(arr)
```
In this example, we convert the Series `s` to a numpy array using `s.values`, and then we can apply the `reshape` method on the numpy array.