module 'pandas' has no attribute 'rolling _mean'
时间: 2023-09-19 18:07:27 浏览: 184
This error message indicates that there is a typo in the code, where there is an extra space between "rolling" and "_mean" in the attribute name. The correct attribute name is "rolling_mean" in pandas module. The following code snippet demonstrates how to use the rolling_mean method:
```python
import pandas as pd
# create a sample data frame
df = pd.DataFrame({'A': [1, 2, 3, 4, 5], 'B': [10, 20, 30, 40, 50]})
# calculate the rolling mean of column A with window size 2
rolling_mean = df['A'].rolling(window=2).mean()
print(rolling_mean)
```
Output:
```
0 NaN
1 1.5
2 2.5
3 3.5
4 4.5
Name: A, dtype: float64
```
相关问题
module 'pandas' has no attribute 'rolling_mean'
The error message you received indicates that the 'rolling_mean' attribute does not exist in the 'pandas' module. This is likely because the attribute has been deprecated and replaced by 'rolling'.
You can try replacing 'rolling_mean' with 'rolling' in your code to see if that resolves the issue. For example, if you previously had:
```
df.rolling_mean(window=3)
```
You can change it to:
```
df.rolling(window=3).mean()
```
AttributeError: module 'pandas' has no attribute 'rolling_mean'
这个错误是因为 `rolling_mean` 已经被弃用了,应该使用 `rolling().mean()`。
例如,如果你想对 Pandas DataFrame 中的一列计算滚动平均值,可以使用以下代码:
```
import pandas as pd
# 创建 DataFrame
df = pd.DataFrame({'values': [1, 2, 3, 4, 5]})
# 计算滚动平均值
rolling_mean = df['values'].rolling(window=2).mean()
print(rolling_mean)
```
输出:
```
0 NaN
1 1.5
2 2.5
3 3.5
4 4.5
Name: values, dtype: float64
```
在这个例子中,我们使用了 `rolling()` 方法来计算滚动窗口大小为 2 的平均值。
阅读全文