I have an existing dataframe, df, where I would like to append several columns and values to if values in the existing columns meet a certain criteria
Data
location type count year
ny marvel 1 2021
ca dc 1 2021
Desired
location type count year strength points cost
ny marvel 1 2021 13 1000 100,000
ca dc 1 2021 10 500 200,000
IF the string in the type column is 'marvel' then strength = 13, points = 1000 and cost = 100,000 IF the string in the type column is 'dc' then strength = 10, points = 500 and cost = 200,000 essentially, I would like to create 3 new columns and add values in these columns based on certain criteria
strength points cost
marvel 13 1000 100,000
dc 10 500 200,000
Doing
#empty dictionary
marvel = {}
dc = {}
marvel_a = {strength:13, points: 1000, cost: 100,000}
dc_a = {strength:10, points: 500, cost: 200,000}
df.assign({'strength': '', 'points': '', 'cost': ''})
I am creating a dictionary that will hold the key and the value and then I am thinking that I need to append this to the existing dataframe, however, the dictionary is working fine, but I am not able to add these 3 new columns.
Any suggestion or advice is appreciated.