'I want to calculate the geoaccumulation index of heavy metals using using for loop and keys function in python

I want to write a function that performs a vector operation (Igeo) on all the columns in dataframe (data1) using a dictionary (sbv2) and the code below:

Igeo = log(data1.el/(1.5*sbv2.el))


for el in sbv2.keys():
    for el in data1.keys():
        data1[str(el)] = np.log(data[el]/(1.5*sbv[el])
    with pd.ExcelWriter('C:\Users\USER\Jupyter_Projects\Data_Analysis\Geochemistry\output\Pollution_Indices.xlsx') as writer:
    
    data1.to_excel(writer,sheet_name="Igeo")
    writer.save()

The code gives the syntax error below:

File "", line 7 with pd.ExcelWriter('C:\Users\USER\Jupyter_Projects\Data_Analysis\Geochemistry\output\Pollution_Indices.xlsx') as writer: ^ SyntaxError: invalid syntax

data1.head sbv2 = {"Hg": 0.056, "V": 53, "Cr":35, "Co": 12, "Ni": 19, "Cu":14, "Zn":52, "As":2, "Cd":0.102, "Pb":17, "U":2.5 }



Solution 1:[1]

don't forget that Python uses '\' as an escape character in strings, so in Windows-style paths '\' should be doubled, as in:

"C:\\Users\\ .... "

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shomeax