-1

I'm using dict(zip(df... to create a dictionary and I get the error below. I've used it exactly in the same way on a different file and it's working fine so not sure why I'm getting this error in here.

To read the mapping file:

df_Mapping = pd.read_excel(r"Z:\Source_Data\Concur_Mapping.xlsx")

To create the dictionary:

dict(zip(df_Mapping.Claim Sub-Type, df_Mapping.Mapping))

Error:

Cell In[71], line 1
dict(zip(df_mapping.Claim Sub-Type, df_mapping.Mapping))
^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

I was expecting to create a dictionary to replace values in another dataframe

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Alicia
  • 3
  • 1
  • What is `Sub-Type` supposed to mean after `df_mapping.Claim`? Did you mean something like `df_mapping["Claim Sub-Type"]`? – mkrieger1 Aug 26 '23 at 20:37
  • Is `.Claim Sub-Type` supposed to be an attribute name? Because it isn't. You've got an embedded space and minus sign in there. – John Gordon Aug 26 '23 at 20:40
  • Thank you so much, guys! df_mapping is the name of the data frame and Claim Sub-Type is the column name. In the past I used it like the below and it did work dict(zip(df.Old, df.New)) df being the dataframe and Old, New the name of the columns – Alicia Aug 27 '23 at 21:41

1 Answers1

0

Most likely, it is because of that space in your column name.

Try:

dict(zip(df_Mapping["Claim Sub-Type"], df_Mapping["Mapping"]))
epursiai
  • 36
  • 5