用得少就会记不得,遂记在此文中
一、创建以时间为索引的表
timeindex1 = pd.date_range(start='2020-09-02 7:00:00',periods=721,freq='10s')
datatime = pd.DataFrame(index=timeindex1)
二、绘制直方图
import matplotlib.pyplot as plt
import numpy as np
datasec['COUNT'].hist(bins=7)
plt.grid(alpha=0.5,linestyle='-.') #网格线
plt.xlabel('carnumbers per 10s')
plt.ylabel('times')
# plt.title('') #+citys[i])
plt.xticks(np.arange(1,7,1))
plt.show()
三、绘制双柱状图
plt.title("possion and p")
plt.xlabel("cars per 10s")
plt.ylabel("probability")
plt.bar(dataE['COUNT'],dataE['psP'], width=0.3, label="possionp")
plt.bar(dataE['COUNT']+0.3,dataE['p'], width=0.3, label="p")
plt.xticks(np.arange(1,7,1))
plt.legend() # 图例
plt.show()
四、计算相关系数
df_PvsPossionP = dataE[['psP','p']]
df_PvsPossionP_corr = df_PvsPossionP.corr()
df_PvsPossionP_corr
五、绘制相关系数热力图
import seaborn as sns
sns.heatmap(df_PvsPossionP_corr, vmax=1, vmin=-1, center=0)
六、处理表格时间的操作
datalpr1 = pd.read_csv("http://____.csv")
datalpr1['TIME'] = pd.to_datetime(datalpr1['TIME'])
datalpr1['H'] = [x.hour for x in datalpr1['TIME']] # 提取时间
datalpr1 = datalpr1[(datalpr1['H']>=8) & (datalpr1['H']<10)]
datalpr1['M'] = [x.minute for x in datalpr1['TIME']]
datalpr1 = datalpr1[['H','M','CID']].groupby(by=['H','M'],as_index=False).count()
七、找出包含某段字符的数据
datain = datalpr[datalpr['ROAD_ID'].str.contains('_4835')]
dataoff = datalpr[datalpr['ROAD_ID'].str.contains('4927_')]
八、merge、时间化秒操作
datacar = pd.merge(dataoff,datain,on='CID')
datacar['TIME'] = datacar['TIME_y']-datacar['TIME_x']
datacar['TIME'] = datacar['TIME'].astype('int64')// 10**9 # 化成秒计
九、merge多个表格
dfs = [df,datas_in_k,datas_out_k] # 连接3个表格(进、出、时间序列表)
datas_k = reduce(lambda x, y: pd.merge(x, y, on="TID", how="outer"), dfs)