SyntaxError: cannot assign to operator

xls = pd.ExcelFile(‘월별매출데이터.xlsx’)
sn = xls.sheet_names
for i,snl in list(zip(range(1,13),sn)):
df+str(i) = pd.read_excel(‘월별매출데이터.xlsx’,sheet_name=snl, skiprows=range(6))

SyntaxError: cannot assign to operator

i want to result as :
df1 = read_excel , list1…
df2 = read_excel… list2… whats the erroe type ,

Hi,

What line is the syntax error pointing to?

Also retry pasting your code in formatted form like this (or at least do so in the future since it’s easier to find syntax errors). You can do this by pressing the </> button.

xls = pd.ExcelFile('월별매출데이터.xlsx')
sn = xls.sheet_names
for i,snl in list(zip(range(1,13),sn)):
   df+str(i) = pd.read_excel('월별매출데이터.xlsx',sheet_name=snl, skiprows=range(6))
1 Like

Pretty sure the syntax error here is from using operators on the left hand side of an assignment; x + x = 3 for example will only ever throw errors. The final line attempts to use this style.

ah nice didn’t catch that…

I was curious about the problem and I had an old excel file to hand so I actually wrote out part of that line when I noticed which was just before you replied :wink:.

@designrockstar65776, probably should add that something like a list might be suitable for this problem. You really don’t want to add numerous similarly named variables if you can avoid it.

1 Like