[英]Most efficient way to prep data for pytorch lstm from pandas dataframe
[英]Python, most efficient way to subplot pandas data frame
我正在尝试绘制9的子图(在此示例中,但是该数字对于其他用例而言是可变的)折线图,显示了按县/地区划分的数据点数量。
到目前为止,我有:
Surrey1 = df[df.county == 'Surrey']
Surrey2 = Surrey1.county.groupby(df.date_stamp).value_counts()
East_Sussex1 = df[df.county == 'East Sussex']
East_Sussex2 = East_Sussex1.county.groupby(df.date_stamp).value_counts()
West_Sussex1 = df[df.county == 'West Sussex']
West_Sussex2 = West_Sussex1.county.groupby(df.date_stamp).value_counts()
Buck1 = df[df.county == 'Buckinghamshire']
Buck2 = Buck1.county.groupby(df.date_stamp).value_counts()
Norfolk1 = df[df.county == 'Norfolk']
Norfolk2 = Norfolk1.county.groupby(df.date_stamp).value_counts()
Suffolk1 = df[df.county == 'Suffolk']
Suffolk2 = Suffolk1.county.groupby(df.date_stamp).value_counts()
Essex1 = df[df.county == 'Essex']
Essex2 = Essex1.county.groupby(df.date_stamp).value_counts()
Kent1 = df[df.county == 'Kent']
Kent2 = Kent1.county.groupby(df.date_stamp).value_counts()
# Create the fig
fig, axes = plt.subplots(nrows=8, ncols=1, figsize=(12,6))
# Now plot
pd1_N.plot(ax = axes[0], subplots=True, legend=False)
pd2_S.plot(ax = axes[1], subplots=True, legend=False)
pd3_ES.plot(ax = axes[2], subplots=True, legend=False)
pd4_WS.plot(ax = axes[3], subplots=True, legend=False)
pd5_B.plot(ax = axes[4], subplots=True, legend=False)
pd6_S.plot(ax = axes[5], subplots=True, legend=False)
pd7_E.plot(ax = axes[6], subplots=True, legend=False)
pd8_K.plot(ax = axes[7], subplots=True, legend=False)
产生:
有没有更快/更有效的方法来做到这一点? 同样,有关如何使图形更具表现力的提示也将不胜感激! 更新:
我现在使用一个非常简单的函数来更快地执行可变指标:
def plot_freq(metric, graph_width, graph_height):
plot = str(metric)
df.groupby(plot)['date_stamp'].value_counts().unstack(0).plot(subplots=True, figsize=(graph_width, graph_height))
print("This plot shows the number of data points by", metric)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.