-1
import pandas as pd
import numpy as np

colors = np.array(['blue','white', 'black', 'blue','white', 'black'])
money = np.array(['666', '777', '888','100', '300', '200'])

df = pd.DataFrame({'AAA': colors, 'BBB': money})
print(df)

output

hello,

what i want basically: where the row equals black, multiply the values on column BBB by 5, where the row equals white, multiply the values on column BBB by 10, and where the row equals blue, divide the values on column BBB by 7

thank you

1 Answers1

0
df['BBB']= df['BBB'].astype('int')
df.loc[df.AAA=='black', 'BBB'] = df['BBB']*5
df.loc[df.AAA=='white', 'BBB'] = df['BBB']*10
df.loc[df.AAA=='blue', 'BBB'] = df['BBB']/7
arpitrathi
  • 157
  • 1
  • 7