'Series' object has no attribute 'reshape'. Did you mean: 'shape'?
时间: 2023-12-25 21:28:56 浏览: 193
当你在使用pandas的Series对象进行reshape操作时,你会遇到错误提示"'Series' object has no attribute 'reshape'. Did you mean: 'shape'?"。这是因为pandas的Series对象没有reshape方法。解决这个问题的方法是将Series对象转化成numpy的ndarray,然后再使用ndarray的reshape方法。
以下是两种解决方案:
1. 使用values方法将Series对象转化成numpy的ndarray,然后使用ndarray的reshape方法。
```python
import pandas as pd
import numpy as np
landmarks_frame = pd.read_csv('faces/face_landmarks.csv')
landmarks = landmarks_frame.iloc[65, 1:]
landmarks = landmarks.astype('float').values.reshape(-1, 2)
```
2. 使用to_numpy方法将Series对象转化成numpy的ndarray,然后使用ndarray的reshape方法。
```python
import pandas as pd
import numpy as np
landmarks_frame = pd.read_csv('faces/face_landmarks.csv')
landmarks = landmarks_frame.iloc[65, 1:]
landmarks = landmarks.astype('float').to_numpy().reshape(-1, 2)
```
阅读全文