Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
With this code:
Python
xls = pd.ExcelFile('test.xlsx')
sn = xls.sheet_names
for i,snlist in list(zip(range(1,13),sn)):
    df+str(i) =  pd.read_excel('test.xlsx',sheet_name=snlist, skiprows=range(6))

I get this error:
> 'df{}'.format(str(i)) =  pd.read_excel('test.xlsx',sheet_name=snlist,
> skiprows=range(6))
>     ^ SyntaxError: cannot assign to function call

I can't understand the error and how solve. What's the problem?
df+str(i) also return error

i want to make result as:
df1 = pd.read_excel.. list1...
df2 = pd.read_excel... list2.... 


What I have tried:

Python
xls = pd.ExcelFile('test.xlsx')
sn = xls.sheet_names
for i,snlist in list(zip(range(1,13),sn)):
    df+str(i) =  pd.read_excel('test.xlsx',sheet_name=snlist, skiprows=range(6))
Posted
Updated 18-Jan-21 1:39am
v2
Comments
Patrice T 17-Jan-21 0:28am    
You need to show enough code to show us the context, and what is skiprows.
Richard MacCutchan 17-Jan-21 5:01am    
just use a simple value for skiprows, instead of the range function.

1 solution

Replace
Quote:
skiprows=range(6)

With
Python
skiprows=[i for i in range(1, 6)]

See pandas.read_excel — pandas 1.2.0 documentation[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900