Answers for "pandas replace encode categorical"

0

pandas replace encode categorical

def encode_data(feature_name):
    ''' 
    This function takes feature name as a parameter and returns mapping dictionary to replace(or map) categorical data with numerical data.
    '''
    mapping_dict = {}
    unique_values = list(rain[feature_name].unique())
    for idx in range(len(unique_values)):
        mapping_dict[unique_values[idx]] = idx
    return mapping_dict

rain['RainToday'].replace({'No':0, 'Yes': 1}, inplace = True)
rain['RainTomorrow'].replace({'No':0, 'Yes': 1}, inplace = True)
rain['WindGustDir'].replace(encode_data('WindGustDir'),inplace = True)
rain['WindDir9am'].replace(encode_data('WindDir9am'),inplace = True)
rain['WindDir3pm'].replace(encode_data('WindDir3pm'),inplace = True)
rain['Location'].replace(encode_data('Location'), inplace = True)
Posted by: Guest on June-29-2021

Code answers related to "pandas replace encode categorical"

Browse Popular Code Answers by Language