![](/img/trans.png)
[英]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.