简体   繁体   中英

Import Excel File Using Pandas

I'm trying to import and excel file that I have stored in a folder within a GitHub repository. Based on that the file path should be

"C:\\Users\\'username'\\Documents\\GitHub\\'repository'\\'folder'\\'filename'.xlsx"

But when I enter the code

import pandas as pd
xlsfile="C:\\Users\\'username'\\Documents\\GitHub\\'repository'\\'folder'\\'filename'.xlsx"
xl1=pd.read_excel(xlsfile,sheet_name='sheet',skiprows=21)

I get an error that says the file path I entered doesn't exist. I know that the entire path to the file exists because my working directory also contains the file, so what could I be doing wrong?

I have no experience coding. Thanks.

Remove the "'" in your filename? Is your sheet really named 'sheet'? I think the default is 'sheet1' ect.

There can be multiple things, as Joe stated you probably don't have ' ' around your file names, I'm assuming that they included those so that you input your local filepath in there (ie replace 'username' with Jack.Donaghue and so on) an example of this would look something like:

"C:/Users/Jack_Donague/Documents/GitHub/YourRepoName/data/datafilename.xlsx"

Also as colbster pointed out to confirm what your sheet is named. I've also experienced some issues with \\ vs / in the file names since I'm working on Windows10.

I would recommend trying

import pandas as pd
xlsfile="C:/Users/'username'/Documents/GitHub/'repository'/'folder'/'filename'.xlsx"
xl1=pd.read_excel(xlsfile,sheet_name='sheet',skiprows=21)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM