Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

 I am trying to create the calculated column based on the min function

x=[[2,3],[1,8],[5,6]]

df_a=pd.DataFrame(x,columns=['a','b'])

df_a["Diff"]=min(df_a['a'],0)-min(df_a['b'],0)

But I am getting the error as below:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

I want to create the column that tells Day over Day increase/decrease of debit values.

1 Answer

0 votes
by (36.8k points)

If min is a Python's min function, I don't think it takes the Pandas series. You can use Pandas' clip to the desired results:

df_a['Diff'] = df_a['a'].clip(upper=0) - df_a['b'].clip(upper=0)

If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch 

Browse Categories

...