数据介绍:
这是一份时序数据。
余额宝用户的申购赎回数据(2013年7月-2014年8月;每天28041位用户,2840421条记录)等信息 预测未来每日的资金流入流出情况
地址:https://tianchi.aliyun.com/competition/entrance/231573/introduction
0、准备工作
import pandas as pd
import numpy as np
import warnings
import datetime
import seaborn as sns
import matplotlib.pyplot as plt
import datetime
from scipy import stats
import warnings
warnings.filterwarnings('ignore')
data_balance = pd.read_csv(dataset_path+'user_balance_table.csv') #读取数据
# 为数据集添加时间戳
data_balance['date'] = pd.to_datetime(data_balance['report_date'], format= "%Y%m%d")
data_balance['day'] = data_balance['date'].dt.day
data_balance['month'] = data_balance['date'].dt.month
data_balance['year'] = data_balance['date'].dt.year
data_balance['week'] = data_balance['date'].dt.week
data_balance['weekday'] = data_balance['date'].dt.weekday
以data分组聚合数据
total_balance =
data_balance.groupby(['date'])['total_purchase_amt','total_redeem_amt'].sum().reset_index()
画出每日总购买与赎回量的时间序列图
import matplotlib.pylab as plt
fig = plt.figure(figsize=(20,6))
plt.plot(total_balance['date'], total_balance['total_purchase_amt'],label='purchase')
plt.plot(total_balance['date'], total_balance['total_redeem_amt'],label='redeem')
plt.legend(loc='best')
plt.title("The lineplot of total amount of Purchase and Redeem from July.13 to Sep.14")
plt.xlabel("Time")
plt.ylabel("Amount")
plt.show()
折线图.png
设定时间段
# 画出4月份以后的时间序列图
total_balance_1 = total_balance[total_balance['date'] >= datetime.date(2014,4,1)]
fig = plt.figure(figsize=(20,6))
...
...
网友评论