python - how to check if pandas dataframe cell contains zeros -
i doing loop go thorugh series in dataframe. want if both cells zero, skip. have skip because want plot output when 2 cells 'cost' , 'new_cost' zero, give me error:
data:
cost new_cost 100.00 25.00 0.00 0.00 3.00 10.00
typeerror: empty 'series': no numeric data plot
this mycode:
if df.cost.isempty , df.new_cost.isempty: continue else: .
this didnt work:
if df[df.cost==0.00] , df[df.new_cost==0.00]: continue else:
but getting valueerror: truth value of dataframe ambiguous. use a.empty, a.bool(), a.item(), a.any() or a.all().
i think want filter dataframe before performing loop (note have enclose boolean conditions in brackets inside indexer):
df_filtered = df[(df.cost != 0) & (df.new_cost != 0)]
Comments
Post a Comment