簡體   English   中英

“if”塊內沒有打印

[英]no printing inside of "if" block

我的杜松子書中有以下代碼。 如果 user_payments 為空,我會收到消息“無信息”。 它工作正常。 但是如果rent_id不為空,關於user_profile的信息(必須打印在if:塊內,不可見。如果我在if-else塊之后添加打印user_profile並且信息存在 - 它顯示正確。

if not user_payments.loc[:,'powerBankRentId'].empty:
    rent_id = user_payments.loc[:,'powerBankRentId'].values[0]
    user_profile['rent_id'] = rent_id
    user_last_rent = table_rents[table_rents['id'] == rent_id]
    user_profile.append(table_rents[table_rents['id'] == rent_id].loc[:,['station_name','createdAt','endAt']])
    user_profile['station_name'] = user_last_rent.loc[:,'station_name'].values[0]
    user_profile['start_rent']   = user_last_rent.loc[:,'createdAt'].values[0]
    user_profile['end_rent']     = user_last_rent.loc[:,'endAt'].values[0]
    user_profile # doesn't print anything
else:
    print('no information')

你能告訴我我如何糾正代碼嗎?

因為它是一行數據框,所以我寫道:

user_profile.head

並得到了預期

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM