1
もっと退屈な質問がここにありますが、誰かが助けてくれることを願っています。私は集計値を曜日別にグラフ化しようとしていますが、曜日の省略形と序列を曜日数で表示しています(つまり、Monを表示するには最初にインデックス0を指定します)。パンダの出力をソートしてプロットするGroupby
def Format_plot(plot):
plot.spines["top"].set_visible(False)
plot.spines["right"].set_visible(False)
plot.yaxis.set_ticks_position("left")
plot.xaxis.set_ticks_position("bottom")
#For purposes of mapping
days = {0:'Mon',1:'Tues',2:'Weds',3:'Thurs',4:'Fri',5:'Sat',6:'Sun'}
ds['signup_weekday'] = ds['signup_dayofweek'].apply(lambda x: days[x])
ds = ds.sort_values(by = 'signup_date')
first_ride_rate = {
'success': lambda x: 1.0*sum(x)/len(x)
}
def GraphMe(item):
de = ds[pd.notnull(ds[item])]
if item == 'signup_weekday':
sorter = 'signup_dayofweek'
else:
sorter = item
de = de.sort_values(by = sorter)
total_avg = 1.0*sum(de['success'])/len(de['success'])
plot = de.groupby(item).agg(first_ride_rate).plot(kind = 'bar',legend=None, title = "Share of signups to complete a first trip")
Format_plot(plot)
plot.axhline(y=total_avg, color = 'orange')
plot.set_xlabel(item)
plot.set_ylabel('Share of Signups to Complete')
print sorter
for item in ['signup_dayofweek','signup_weekday']:
GraphMe(item)
あなたはそれが私が週指数の日にしたいと、注文誰かが巧妙なハックを持って望んでいません見ることができるように。また、スタックオーバーフローにジュピターノートセルを入力する簡単な方法があれば、さらなる質問を知ることができます。
ありがとうございます!
感謝を追加します!おそらくかなり明白ですが、私は一般的にPythonの方が新しいです。 はAttributeError:私は今もののATTRエラーを取得しています 「AxesSubplot」オブジェクトが属性「set_xlabels」 を持っていない私は、このかかわらずに探しておこうが –
あまりにも難しいことではありません私は申し訳ありませんが、私は_xを意味しました**ティック**のラベル。答えを訂正しました。 – ImportanceOfBeingErnest
あなたは美しい人間であり、今は私のグラフがほぼ美しいです。ありがとうございました! –