由于代码中注释已经非常的清晰,文章中就不过多叙述了,直接上代码。
代码如下:
# 在开始之前先导入所需要的包
import warnings # `do not disturbe` mode
warnings.filterwarnings('ignore')
import numpy as np # vectors and matrices
import pandas as pd # tables and data manipulations
import matplotlib.pyplot as plt # plots
import seaborn as sns # more plots
from dateutil.relativedelta import relativedelta # working with dates with style
from scipy.optimize import minimize # for function minimization
import statsmodels.formula.api as smf # statistics and econometrics
import statsmodels.tsa.api as smt
import statsmodels.api as sm
import scipy.stats as scs
from itertools import product # some useful functions
from tqdm import tqdm_notebook
from sklearn.metrics import r2_score, median_absolute_error, mean_absolute_error
from sklearn.metrics import median_absolute_error, mean_squared_error, mean_squared_log_error
%matplotlib inline
# 准备好数据,读取文件
# 注意:这里的文件路径的斜杠与windows相反
ads = pd.read_csv('C:/Users/xxxx/Desktop/ads.csv', index_col=['Time'], parse_dates=['Time'])
currency = pd.read_csv('C:/Users/xxxx/Desktop/currency.csv', index_col=['Time'], parse_dates=['Time'])
# 这里使用的pandas的read_csv
# 查看导入的ads文件
ads.head()
运行结果如下:
# 查看导入的currency文件
ads.head()
运行结果如下:
# 查看ads的统计学描述,可以查看共有多少数据、均值、标准差、最小值、25%、50%、75%、最大值等等
ads.describe()
运行结果如下:
# 利用plt画图
plt.figure(figsize=(15, 7))
plt.plot(ads.Ads)
plt.title('Ads watched (hourly data)')
plt.grid(True)
plt.show()
# 同理
plt.figure(figsize=(15, 7))
plt.plot(currency.GEMS_GEMS_SPENT)
plt.title('In-game currency spent (daily data)')
plt.grid(True)
plt.show()