Q:

Lambda + Apply to get two new columns in Pandas

I have df looks like:
Name                 Item
A,D,B,B,C,C      I1,I2,I3,I1,I2
X,Y,Z,Z,Z            I4,I1,I1,I88,I4 

Expected Output:
Name            Item         Unique_Name  Unique_Item Count_Unique_name  Count_Unique_Item
A,D,B,B,C,C  I1,I2,I3,I1,I2    A,B,C,D      I1,I2,I3         4             3             
X,Y,Z,Z,Z   I4,I1,I1,I88,I4    X,Y,Z       I4,I1,I88         3             4

Code:
new_items_df['Unique_Name'] = new_items_df['Name'].apply(lambda x: set(x.lower().split(",")))
new_items_df['Unique_Item'] = new_items_df['Item'].apply(lambda x: set(x.lower().split(",")))
new_items_df['Count_Unique_Name'] = new_items_df['Unique_Modifier'].apply(lambda x: len(x))
new_items_df['Count_Unique_Item'] = new_items_df['Unique_Item'].apply(lambda x: len(x))

The above code works fine but I am doing same operation and running the same code twice. When I am trying to merge the 1st two lines of code like below:
new_items_df[['Unique_Name','Unique_Item']] = new_items_df[['Name','Item']].apply(lambda x: set(x.str.lower().str.split(",")),axis =1)

TypeError: ("unhashable type: 'list'", 'occurred at index 0')

I tried to use .unique()also, tried converting that as a list by using [], but nothing seems to work, I am getting one error or another
Summarize:
So, Can I get a help in combining my 4 lines of code to 1 line ?

A:

You can working with scalars with applymap:
c = ['Name','Item']
#python 3.6+ solution
c1 = [f'Unique_{x}' for x in c]
c2 = [f'Count_Unique_{x}' for x in c]
#python bellow 3.6
#c1 = ['Unique_{}'.format(x) for x in c]
#c2 = ['Count_Unique_{}'.format(x) for x in c]

new_items_df[c1] = new_items_df[c].applymap(lambda x: set(x.lower().split(",")))
new_items_df[c2] = new_items_df[c1].applymap(len)

print (new_items_df)
              Name             Item   Unique_Name    Unique_Item  \
0  A,A,A,B,B,B,C,D   I1,I2,I3,I1,I2  {c, b, d, a}   {i1, i2, i3}   
1        X,Y,Z,Z,Z  I4,I1,I1,I88,I4     {y, x, z}  {i1, i4, i88}   

   Count_Unique_Name  Count_Unique_Item  
0                  4                  3  
1                  3                  3  

