Python Forum

Full Version: Iteration Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi;

i create a code for find a replace words of a list. But i had a proble in the iterarion of this code, only change the first word

def dictionary_unique(df, file, column = 'Word'):
    
    dictionary = pd.read_csv(file, dtype=str, encoding='latin1', sep=';')
    df = df[column].values.tolist()
    read_words = dictionary['Word_Comp'].values.tolist()
    replace_word = dictionary['Replace'].values.tolist()
    
    elem = {k: i for i, k in enumerate(df)} 
    Output = list(map(elem.get, read_words))
    
    
        
    for index, replacement in zip(Output, replace_word):
        df[index] = replacement
        
        return df
please HELP