I've tried to open a file that does exist but I keep getting an error message of:
No such file or directory on Mac
I have made sure it is in the same directory as the python code. I've also tried changing the name of the excel doc and whether the doc is .xls
and .xlsx
but it has not worked.
Here are several versions I've tried, but so far they all give me the same result.
import os.path
book = open(os.path.expanduser("~/Desktop/Crimes.xlsx"))
or
import xlrd
import os.path
book = xlrd.open_workbook(os.path.join("/Users/caitlinwesterfield",'Crime.xls')
or
import xlrd
book = xlrd.open_workbook('Crime.xls')
or
import xlrd
book = open('/Users/caitlinwesterfield/Desktop/Crime.xls', "r")
or
import xlrd
book = open("~/Crime.xls", "r")
or
import xlrd
book = open(os.path.expanduser(r"~/Desktop/Crime.xls"))
or
import xlrd
book = open('Crime.xls')
or
import xlrd
book = open(os.path.expanduser("/Users/caitlinwesterfield/Desktop/Crime.xls"))
or
import xlrd
import os
book = xlrd.open_workbook(os.path.join("/Users/caitlinwesterfield","TypesOfCrime.xls"))
or
import xlrd
book = xlrd.open_workbook("typesofcrime.xls")