0

enter image description here

enter image description here

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

I have this :

TypeError: argument of type 'int' is not iterable

how can I fix it ?

3
  • Can you create minimal, complete, and verifiable example ? Commented Jan 22, 2019 at 9:16
  • What nb_products_per_basket['InvoiceNo'] contains? Provide an example, please Commented Jan 22, 2019 at 9:16
  • I update the question Commented Jan 22, 2019 at 9:22

1 Answer 1

1

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 strings 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.