请教FutureWarning:mad和save方法无效如何更改

‘’‘
FutureWarning1: The** 'mad' **method is deprecated and will be removed in a future version. To compute the same result, you may do (df - df.mean()).abs().mean().

FutureWarning2: save is not part of the public API, usage can give unexpected results and will be removed in a future version
xwf.save()
’‘’





import pandas as pd

import openpyxl as ol
import xlsxwriter as xl

import numpy as np

import seaborn as sns
import matplotlib.pyplot as plt

import statsmodels.api as sm


def status(x) :
    return pd.Series([x.count(),x.min(),x.idxmin(),x.quantile(.25),x.median(),x.quantile(.75),x.mean(),x.max(),x.idxmax(),x.mad(),x.var(),x.std(),x.skew(),x.kurt()],index=['总数','最小值','最小值位置','25%分位数', '中位数','75%分位数','均值','最大值','最大值位数','**平均绝对偏差**','方差','标准差','偏度','峰度'])
comcon=pd.read_excel('C:\\Users\\86135\\Desktop\\计量经济学\\课程数据库\\2comcon.xlsx')
y=comcon.comcon
x=comcon.avgdp
print(comcon)

df = pd.DataFrame(np.array([x,y]).T, columns=['x','y'])
print(df.apply(status))
wdata=df.apply(status)
xwf=pd.ExcelWriter('C:\\Users\\86135\\Desktop\\计量经济学\\课程数据库\\2comdescribe(每次运行要新的,记得换名称).xlsx', engine='xlsxwriter')
wdata.to_excel(xwf,sheet_name='data',index=True)
**xwf.save()**

sns.pairplot(comcon,x_vars='avgdp',y_vars='comcon',kind='reg')
plt.title('scatter')
plt.show()


x=sm.add_constant(x)
model=sm.OLS(y,x)
results=model.fit()
print(results.summary())

将save()改成close() !因为save已经不公开给用户使用了,你用close一样的它内部会调用内部的save。
至于mad没看到你用啊,你没用怎么会有警告。

这只是warning,不是error,只print一个错误信息,不抛异常,不影响运行
意思就是这两个函数准备废弃了,暂时还能用,但是如果版本升级就会不再支持,所以为了兼容性最好是改掉