Skip to content

Instantly share code, notes, and snippets.

@Kamaldeep0077
Created December 6, 2020 10:15
Show Gist options
  • Save Kamaldeep0077/9d139da8567d4eab48c2006d3da9894d to your computer and use it in GitHub Desktop.
Save Kamaldeep0077/9d139da8567d4eab48c2006d3da9894d to your computer and use it in GitHub Desktop.
# Frequency encoding using value_counts function
Item_Type_freq = data['Item_Type'].value_counts(normalize=True)
# Mapping the encoded values with original data
data['Item_Type_freq'] = data['Item_Type'].apply(lambda x : Item_Type_freq[x])
print('The sum of Item_Type_freq variable:', sum(Item_Type_freq))
data[['Item_Type', 'Item_Type_freq']].head(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment