There is problem one, multiple or all values are integers in column InvoiceNo
.
Possible solution if mixed column values ( C
are in another values not shown in sample data) is cast it to string
s by astype
:
nb_products_per_basket['order_canceled'] =
nb_products_per_basket['InvoiceNo'].astype(str).apply(lambda x:int('C' in x))
Another solution with str.contains
:
nb_products_per_basket['order_canceled'] =
nb_products_per_basket['InvoiceNo'].str.contains('C', na=False).astype(int)
If all values are integers there are no C
, so always get 0
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.