‘’‘
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())