0

In my data frame there are two columns and they are obj type.

index COLOUR CATEGORY
0 blue iphone11
1 black iphone12
iphone_sale['COLOUR'] = iphone_sale['COLOUR'].astype(str)
iphone_sale['CATEGORY'] = iphone_sale['CATEGORY'].astype(str)

I need to create a new column using above both columns.

iphone_sales_sum["colour_category"] = iphone_sales_sum.apply(lambda x: f"{x['COLOUR']} /{x['CATEGORY']}", axis=1)

But I am getting a noisy values as the derived column.

iphone 12\nName: 0, dtype: object/... etc

But it doesn't give any error i lmbda function.This code perfectly worked for an other scenario.

2
  • what do you mean with noisy values Commented Apr 13, 2022 at 14:26
  • @NikolayTsvetanov iphone 12\nName: 0, dtype: object/..blue\nName: 0, dtype: object/ Values in derived column are like this Commented Apr 13, 2022 at 18:27

1 Answer 1

1

when i reproduce your code:

import pandas as pd
iphone_sales_sum = pd.DataFrame([[1,"blue", "iphone 12"],[2,"black","iphone12"],[3,"sad3","jkl3"]], columns=["index",'COLOUR', 'CATEGORY' ])
iphone_sales_sum['COLOUR'] = iphone_sales_sum['COLOUR'].astype(str)
iphone_sales_sum['CATEGORY'] = iphone_sales_sum['CATEGORY'].astype(str)
iphone_sales_sum['colour_category'] = iphone_sales_sum.apply(lambda x: f"{x['COLOUR']} / {x['CATEGORY']}", axis=1)

i get

colour_category
blue / iphone 12
black / iphone12
sad3 / jkl3
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.