我有以下功能:
def Graphs(brand,delegation_date,geo):
plt.figure(figsize = (25,10))
if delegation_date == '2019-04':
plt.title(brand + " Apr to Sep 2019 " + geo)
elif delegation_date == '2019-10':
plt.title(brand + " Oct 2019 " + geo)
else:
plt.title(brand + " Before Apr 2019 " + geo)
g = temp3.loc[(temp3.Brand == brand) & (temp3.delegation_date == delegation_date),'Green'].tolist()[0]
y = temp3.loc[(temp3.Brand == brand) & (temp3.delegation_date == delegation_date),'Yellow'].tolist()[0]
r = temp3.loc[(temp3.Brand == brand) & (temp3.delegation_date == delegation_date),'Red'].tolist()[0]
gp_grouping = temp3[(temp3['Brand'] == brand) & (temp3['delegation_date'] == delegation_date) & (temp3['geo'] == geo)].groupby(['margin_percentage_floor']).agg({'bid_reference_number':pd.Series.nunique}).reset_index()
gp_grouping_1 = temp3[(temp3['Brand'] == brand) & (temp3['Sale_Flag'] == '1') & (temp3['delegation_date'] == delegation_date) & (temp3['geo'] == geo)].groupby(['margin_percentage_floor']).agg({'bid_reference_number':pd.Series.nunique}).reset_index()
plt.plot(gp_grouping['margin_percentage_floor'],gp_grouping['bid_reference_number'])
plt.plot(gp_grouping_1['margin_percentage_floor'],gp_grouping_1['bid_reference_number'])
plt.axvspan(g, maxval, facecolor='g', edgecolor = 'none', alpha=.2)
plt.axvspan(y, g, facecolor='r', edgecolor='none', alpha=.2)
plt.axvspan(minval,y, facecolor='purple', edgecolor='none', alpha=.2)
plt.axvline(float(temp3[(temp3['Brand'] == brand) & (temp3['delegation_date'] == delegation_date)].margin_percentage_floor.median()), color='k', linestyle='--')
plt.gca().invert_xaxis()
picture = (brand + "." + str(delegation_date)) + '.png'
plt.savefig('C:/Users/rvaka/Desktop/Graphs/' + picture, dpi = 300)
我试图通过这个函数运行一个for循环,看起来像这样:
def dplots(geo):
for i in brands:
for j in delegation_dates:
Graphs(i,j,geo)
其中品牌和委托日期是循环遍历的列表。plt。title不断返回else语句(“在2019年4月之前”…),但它不应该只返回那个title。谁能告诉我为什么会这样? 问题来源StackOverflow 地址:/questions/59382115/if-else-statement-in-function-is-not-running-properly
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。