將解析的 JSON 與數(shù)據(jù)庫中的表數(shù)據(jù)進行比較。我能夠成功比較數(shù)據(jù),但下面是澄清/幫助: eventtime _merge0 2019-09-01 02:02:01 both1 2019-09-01 02:02:17 both2 2019-09-01 02:02:22 left_only因此,“_merge”列會告訴我數(shù)據(jù)是否與所有行匹配。1) 如果輸出(_merge 列)給出所有記錄為“兩者”,則應(yīng)為“通過”情況 2)如果輸出(_merge 列)給出至少一條記錄而不是“兩者”,則應(yīng)為“失敗”的案例。 df_values = final_list['_merge'].to_string(index=False) print (df_values) if 'both' not in df_values: print ("failed") if 'both' in df_values: print ("Pass")以上代碼在多種情況下不一致。
1 回答

茅侃侃
TA貢獻1842條經(jīng)驗 獲得超21個贊
您可以使用 'all' 來檢查所有值是否都等于 'both' :
df_values = final_list['_merge']
if all([val == 'both' for val in df_values]):
print('Pass')
else:
print('failed')
這可以濃縮為
if all(final_list['_merge']=='both'):
print('Pass')
else:
print('failed')
添加回答
舉報
0/150
提交
取消