0

在此处输入图像描述

在此处输入图像描述

 nb_products_per_basket['order_canceled'] =            
 nb_products_per_basket['InvoiceNo'].apply(lambda x:int('C' in x))

我有这个 :

TypeError: argument of type 'int' is not iterable

我该如何解决?

4

1 回答 1

1

问题一,多个或所有值都是 column 中的整数InvoiceNo

如果混合列值(C在示例数据中未显示的另一个值中)被转换为strings 的可能解决方案astype

nb_products_per_basket['order_canceled'] =            
nb_products_per_basket['InvoiceNo'].astype(str).apply(lambda x:int('C' in x))

另一个解决方案str.contains

nb_products_per_basket['order_canceled'] =            
nb_products_per_basket['InvoiceNo'].str.contains('C', na=False).astype(int)

如果所有值都是整数,则没有C,所以总是得到0

于 2019-01-22T09:24:00.910 回答