Change values of a particular column to value_count() Suppose i have the following data set. I need to replace the value of a particular column by the value_count(). I saw few posts where it is done for the entire data set. I need to do it for a particular column.

data = pd.DataFrame({'Item 1': ['apple', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'egg'],
          'Item 2': [1,5,2,7,8,4,9,0,3],
          'Item 3': ['a','b','a','c','d','c','e','e','e']})


How do i replace the values of column 'Item 1' by the value_counts()?

I tried the following code.

data.apply(lambda x: x.map(x.value_counts()))


But this is applying to whole data. I need to do it for one column.

The resulting value should be of the form - 

'Cheese':3

'Potato':2
Try this:

# Do value_count outside of loop to avoid doing it multiple times
vc_item1 = data['Item 1'].value_counts()

data['Item 1'].apply(lambda x: vc_item1[x])


But if understand your comment correctly you want both key and value in each cell:

vc = data['Item 1'].value_counts()

data['Item 1'].apply(lambda x: str(x) + ':' + str(vc[(x)]))