0

I have a dataframe which I'd like to adjust the values which are associated with a string from a different column. Example, all values in column 'wgt' that is associated with 'joe' in the 'name' column to multiply 1.10.

original df

name wgt
joe 10
gary 8
pete 12
pete 13
pete 14
joe 11
gary 7
gary 5
gary 7

adjusted df

name wgt
joe 11
gary 8
pete 12
pete 13
pete 14
joe 12.1
gary 7
gary 5
gary 7

code for sample df

import pandas as pd
data = {'name':['joe','gary','pete','pete','pete','joe','gary','gary','gary'
],'wgt':[10,8,12,13,14,11,7,5,7,]}
df = pd.DataFrame(data)
df

thanks in advance

0

1 Answer 1

2
df['wgt'] = np.where(df.name == "joe", df.wgt * 1.1, df.wgt)

or

df.loc[df.name == "joe", "wgt"] *= 1.1
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.