Python 数据处理练习

Python 数据处理练习_第1张图片

代码:

import random

import numpy as np
import scipy as sp
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

import statsmodels.api as sm
import statsmodels.formula.api as smf

anascombe = pd.read_csv('anscombe.csv')

print(anascombe.groupby('dataset')['x','y'].mean())
print(anascombe.groupby('dataset')['x','y'].var())

lin_model = smf.ols('y ~ x', anascombe).fit()
print(lin_model.summary())

g = sns.FacetGrid(anascombe, col='dataset')
g.map(plt.scatter, 'x', 'y')
plt.show()

运行结果:

Python 数据处理练习_第2张图片

Python 数据处理练习_第3张图片

你可能感兴趣的:(Python 数据处理练习)