I used r' in front of the string so that Python doesn't treat the backslashes as escape sequences.
df.to_excel(r'C:\Users\A\Desktop\Data\file.xlsx', index = False) #exporting to excelfile named "file.xlsx"
However, this time I need the filename to be a variable instead. I usually format it by using F-string but I can't combine the r' and f' together. It doesn't work
df.to_excel(r'f'C:\Users\A\Desktop\Data\{filename}.xlsx'', index = False)
How can i solve this? Thanks
rf'C:\Users\A\Desktop\Data\{filename}.xlsx'