Created
December 6, 2020 10:15
-
-
Save Kamaldeep0077/9d139da8567d4eab48c2006d3da9894d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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