Error! blahfile is not UTF-8 encoded. Saving disabled
The very simple answer to this is none of the above. This is a very misleading error message, especially when the code you've written was designed to save a binary file with a weird extension.
What this actually means is ...
I HAVE NO IDEA HOW TO DISPLAY THIS DATA ! - Yours Jupyter
So, go to your File Explorer, Finder navigate to the just saved file and open it. Voila !!
Everything worked exactly as planned, there is no error.
Hope this saves other people many hours of debugging, and please Jupyter, change your error message.
How to avoid problem with encode UTF-8 error
There is nothing wrong with the program itself. You are getting this error because you are trying to read a file which is not encoded as UTF-8 as UTF-8-encoded. You have to either convert the contents of the file to UTF-8 or specify a different encoding (the one that the file actually uses) in the call to open
.
Unreadable Notebook NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n {\\n "cell_type": "...',)
I just had the same issue after upgrading from IPython 0.13 (ish) to Jupyter 4.
The problem in my case were a few rogue trailing commas in the JSON, for example the comma following "outputs" in:
...
"language": "python",
"metadata": {},
"outputs": [],
},
After removing the commas, Jupyter/IPython could again read the notebook (and upgraded it to version 4). I hope this helps.
UnicodeDecodeError when reading CSV file in Pandas with Python
read_csv
takes an encoding
option to deal with files in different formats. I mostly use read_csv('file', encoding = "ISO-8859-1")
, or alternatively encoding = "utf-8"
for reading, and generally utf-8
for to_csv
.
You can also use one of several alias
options like 'latin'
or 'cp1252'
(Windows) instead of 'ISO-8859-1'
(see python docs, also for numerous other encodings you may encounter).
See relevant Pandas documentation,
python docs examples on csv files, and plenty of related questions here on SO. A good background resource is What every developer should know about unicode and character sets.
To detect the encoding (assuming the file contains non-ascii characters), you can use enca
(see man page) or file -i
(linux) or file -I
(osx) (see man page).
os.getcwd() leading to FileNotFoundError
Use os.path.join instead of specific concatenation
Use shutil to move (instead of MV)
Use os.mkdir to make directory
Specify FileExistsError in error handling on mkdir
Related Topics
How to Replace Nan Values Where the Other Columns Meet a Certain Criteria
How to Get Python to Detect for No Input
Splitting Strings into Numbers (Python)
Python: Read Several Json Files from a Folder
How to Save Opened Page as Pdf in Selenium (Python)
Read Multiple Images on a Folder in Opencv (Python)
Replace a Word in a String by Indexing Without "String Replace Function" -Python
How to Delete Lines from CSV File Using Python
Python, Deleting All Files in a Folder Older Than X Days
Django Development Server, How to Stop It When It Run in Background
How to Use Anaconda Python to Execute a .Py File
Pyspark Replace All Values in Dataframe With Another Values
How to Center a Window on the Screen in Tkinter
Splitting Dictionary Items into Smaller Dictionaries Based on Condition
How to Track the Number of Times a Function Is Called
Plot Two Histograms on Single Chart With Matplotlib
Type Conversion in Python Attributeerror: 'Str' Object Has No Attribute 'Astype'