记录一下摸索数据处理的过程
首先引入包、读取数据并预览:
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
data = pd.read_csv('t_order.csv')
print(data.head())
接下来将日期列转化为时间格式、设置日期索引,再对数据按照shop_id分组,对sale_amt按照月求和
data['ord_dt'] = pd.to_datetime(data2['ord_dt'])
data = data.set_index('ord_dt')
dataNew = data.groupby(['shop_id'])[['sale_amt']].resample('M',how = sum)