0

I have variables with values:

A = 1.05
B = 1.07
C = 1.09
D = 1.2
E = 1.25
F = 1.27

and the DataFrame -> column 'suf'.

I need to create new column, for example df['suf_values'] and insert the corresponding values from the variables -> screenshot:

enter image description here

I will be grateful for the help

Alex
  • 147
  • 8
  • Store your associations in a dictionary (which can be programmatically built if needed) then [`map`](https://pandas.pydata.org/docs/reference/api/pandas.Series.map.html) -> `df['suf_value'] = df['suf'].map({'A': 1.05, 'B': 1.07, 'C': 1.09, 'D': 1.2, 'E': 1.25, 'F': 1.27})` – Henry Ecker Nov 14 '21 at 17:45
  • corresponding = {'A':1.05, 'B':1.07, 'C':1.09, 'D':1.2, 'E':1.25, 'F':1.27} df = pd.DataFrame({"suf": ['A', 'D', 'F', 'E', 'B','C', 'A', 'D', 'D', 'F']}) df["suf_value"] = df["suf"].map(corresponding) – Esa Tuulari Nov 14 '21 at 17:53

0 Answers0