change a value in a csv file using pandas python without knowing its index

Question:

I need to change a value in csv file without knowing its index

but by using another value in the same row

df = pd.read_csv("dataframe.csv")
        result = df[df['USERNAME'] == login.user_name]
        result = result['CARD_BALANCE'].values[0]
        if result>=20:
           a=result+100
           df.loc[df['USERNAME'] == result, "CARD_BALANCE"] = a  
           df.to_csv('dataframe.csv', index=False)

THIS IS NOT WORKING. HELP ME

Asked By: Kanishka.R

||

Answers:

Your code is almost work, you just change one line from

df.loc[df['USERNAME'] == result, "CARD_BALANCE"] = a 

become

df.loc[df['USERNAME'] == login.user_name, "CARD_BALANCE"] = a 
Answered By: Jordy
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.