[PMT]Select dataframe by multiple conditions

xiaoxiao2021-09-18  99

It’s easy to select a part of dataframe by one condition like below.

pos = df_train[df_train['Date']>0]

But when you are trying to add conditions like this

pos = df_train[df_train['Date']>0 and df_train['Coupon_id']>0]

You get error like this.

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

The right way to write it

pos = df_train[(df_train['Date']>0) & (df_train['Coupon_id']>0)] [1]: https://blog.csdn.net/destiny_python/article/details/78675036
转载请注明原文地址: https://www.6miu.com/read-4823625.html

最新回复(0)