tried r and \ in df=pd.read_csv(“C:\Users\Hp\Attrition.csv”). even moved attrition file to the same folder as the notebook. Nothing works. kindly help.
p.s. I am new to jupyter
I’m not sure why you are moving the file and expecting a solution?
You’d get File Not Found error or an error about the path if it was having trouble locating the file.
So is the title related to the issue or not?
Please read Getting good answers to your questions and reply with actual details. For example, under the section ‘Help others reproduce the problem’, in the link to How do I ask a good question? at the bottom there, it clearly states to supply the code and the complete error trace.
Finally, are you sure this is a Jupyter issue? If not, it is pertinent to other places and not here. I suspect if you ran the same Python code directly in Python console or invoking Python to run the code in a script, the more traditional ways to use Python, you’d have the same issue, which means it isn’t Jupyter.
How do I ask a good question? details that you are to ‘Search, and Research’. What have you looked up about the error and what have you tried that would be salient to that issue? For example, did you try things detailed [here in reply to ’ UnicodeDecodeError when reading CSV file in Pandas’? Detail that in a reply if it ends up being pertinent to here.
i am not getting File Not Found error
the UnicodeDecodeError says: ‘utf-8’ codec can’t decode byte 0xe3 in position 14: invalid continuation byte
The entire error unable to paste here. But I tried encoding=‘utf-8’. That too did not work. I am missing something simple but crucial and I just can’t understand it.
Yes, you already knew that according to:
It clearly is not utf-8 encoding. There’s a number of them you can try. There’s a whole list of them in that thread I referenced, see there.
Yeah tried all those. Not working. Some showing the same error as stated previously and others showing parser error. If there is more encoding to try I can give it a shot.
There’s code there with a list that will try all. Did you do that?
If you did, then it probably isn’t a .csv
file.
Have you opened it in a coding text editor to see what it says? A true .csv
file is a variation on a text file. If you cannot read it in any context then it isn’t correctly labeled & may be binary or possibly corrupt.
When trying to open the file in microsoft excel a message is displayed ‘the file format and extension of attrition.csv don’t match. The file could be unsafe or corrupt’. However when I ignore the warning and press yes it opens without hassle. when it is opening in notepad, it is displaying gibberish. The file was created by someone on macbook and now i am trying to open it in windows.
It sounds like it is a binary Excel file then that has been mislabeled. It pretty much says what this has all lead back to with ‘the file format and extension of attrition.csv don’t match. The file could be unsafe or corrupt’
.
Please go back and read the first link I provided , Getting good answers to your questions , because I am left here scratching my head that you had this information all along and thought not to share it?
Anyway…
So after you open it, save/export it as an actual comma-separated file from Excel and you should be able to use the text based file anywhere. It should then open in Notepad, that you mention, as text. (Hopefully you meant Notepad++, and not Microsoft Notepad. Anything Microsoft has, except finally VSCode, opens & saves with special things that will cause you headaches when you try to work with them in Python. You’ll be confused. Please use a proper code editor, if you aren’t already.)
As I had mentioned before I am new to jupyter, rather I am new to coding itself. Perhaps I was not detailed about my inexperience. Anyhow I saved it as csv and now its opening. Thanks for that. It was only after you suggested about coding text editor that I thought may be its important to share the info regarding the message displayed when opening the file. Also since the contents would display I thought there wasn’t anything wrong with the file itself. Anyway, thanks for your support.
Great point.
One thing that you can also probably take away from this, that was out of your hands here, is that poor handling of naming files can cause issues rather far downstream.
Yes. I understood that. Thanks again.