Python Forum
Iteration Help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Iteration Help (/thread-25732.html)



Iteration Help - jareyesluengo - Apr-09-2020

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