i got a permission denied error while i tried to open an excel file.
I dont have the ms excel complete version. I mean, im just using the trial version.
Could it be because of that?
my code has just 4 lines
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
dataset = pd.read_excel("E:\\ML")
It's something about how file open function works. I successfully reproduced your problem and find the way.
It's believed that you have a directory named ML in E disk, and maybe there are some excels files (such as *.xls or *.xlsx) in ML(I bet you just started learning machine learning). Now you try to load the excel data into your program, but you give the path E:\\ML, which is a directory instead of a file, so operation is forbidden by system when pandas try to serialize the directory as a file, which is the cause of error "Permission denied".
The method is that you're supposed to use file path like E:\\ML\\your_database_file_name.xls.
I hope it will work for you.
For me, it turns out that it was because I had the same Excel file opened (I kept getting the error while trying to push my work to Github) which was resolved immediately after I closed the MS Excel (the program using the file I wanted to push..)
I hope you find this helpful!
Related
I am trying to read an excel sheet and create a pandas data frame out of it, but it keeps saying that the sheet does not exist, even tho it actually exists. Has anyone faced something similar?
This is the code I used:
excel=pd.ExcelFile("Berlin_Club_List.xlsx")
clubs=pd.read_excel(excel, 'Berlin_Club_List')
Is the file in your working directory?
If it is not you need to provide full path
(Would be a comment but not enough rep)
To check your actual working directory you can do the following:
import os
os.getcwd()
Do show the actual error message that you got. This will help others to understand and debug the issue you are facing.
Definitely check the documentation for pd.read_excel by typing
pd.read_excel?
you will see that you can specify the sheet you want to by
pd.read_excel(excel, sheet_name='sheetname')
and so on.
I have written a code which combines some CSV files into a single Excel file, and ended the 'writer' with the code:
writer.save()
writer.close()
However, I get the following error when trying to then open that file after the code has finalised:
We found a problem with some content in 'the file.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.'
This seems to purely be related to the 'Writer.Close()' aspect, as without it I don't get the error. However, instead I cannot open the file as it states that someone else is using it (ie - openpyxl)
I'm not sure if relevant, but my file system runs on a OneDrive cloud based system.
My current plan beyond the 'writer.close()' is to pause the script to allow me to print the excel to PDF (I found this to be unreliable via Python), and then 'hit continue' to continue with exporting the PDF via Email.
Any ideas on how to resolve this error?
With out seeing more of your code and maybe an example of the data you are writing it's tough to make any assumptions. Based on the error you are experiencing it is likely due to the inputs/data going into the actual xlsx file that is causing the issue and not with the actual 'writer'. This is Excel saying that data in your file is 'corrupted' from their standards perspective and needs to be fixed.
You should be able to do a 'recovery' of the file through excel and it will identify the problem spots in your file which you can then back track into your python program and properly address to eliminate the probelm.
I am currently having a d.npz file that was born from Python that I would like to load it into R. I tried using the package RcppCNPy, but when I run load("d.npz"), it gave me this error message:
bad restore file magic number (file may be corrupted) -- no data loaded
I tried other tools like source("d.npz") or readRDS("d.npz"), but none worked out. Could anyone please help me solve this seemingly simple problem??
I tried the following code to be able to read an excel file from my personal computer.
import xlrd
book = xlrd.open_workbook('C:\\Users\eline\Documents\***\***\Python', 'Example 1.xlsx')
But I am getting the error 'Permission denied'. I am using windows and if I look at the properties of the directory and look at the 'Security' tab I have three groups/users and all three have permissions for all the authorities, except for the last option which is called 'special authorities' (as far as I know I do not need this authority to read the excel file in Python).
I have no idea how to fix this error. Furthermore, I do not have the Excel file open on my computer when running the simulation.
I really hope someone can help me to fix this error.
Sometimes, it is because you try to read the Excel file while it is opened. Close the file in Excel and you are good to go.
book = xlrd.open_workbook('C:\\Users\eline\Documents\***\***\Python', 'Example 1.xlsx')
You cannot give path like this to xlrd. path need to be single string.
If you insist you can use os module
import os
book = xlrd.open_workbook(os.path.join('C:\\Users\eline\Documents\***\***\Python', 'Example 1.xlsx'))
[Errno13] permission denied in your case is happening because you want to read folder like a file which is not allowed.
I ran into this situation also while reading an Excel file into a data frame. To me it appears that it is a Python and/or Excel bug which we should probably not hide by using os.path.join even if that solves the problem. My situation involved an excel spreadsheet that links cells to another CSV file. If this excel file is freshly opened and open when I try to read it in python, it fails.
Python reads it correctly if I do an unnecessary save of the open Excel file.
I am trying to loop over Excel files with python pandas. First I'm saving them to csv and then I open them again, slice and then saving them again. But I get an error:
"Workbook: size exceeds expected 10752 bytes; corrupt?"
I am relatively new to python.
I could fix this exact error by just opening the problematic Excel file in Excel and simply saving it.
After that I could import the file in Pandas without the error.
In my case I suspect that this error results from a platform inconsistancy in Excel between Windows (where my source files were generated) and Mac OS (where I import the files).
I think you may have a cell that has more than 255 characters in it.
See this article about data and file size limitations: http://kb.tableau.com/articles/knowledgebase/jet-data-file-size-limitations
Consider using openpyxl to open your Excel files instead.
It seems that pandas uses xlrd to read excel files and xlrd raises an error if it feels something is wrong about reading the file... which is what happened to you.
xlrd is no longer maintained as of Jan 2020.