Recently, there have been many opportunities to collect sensor data on an Android device, convert it from JSON format to CSV format using Python, and format the data.
So, I got stuck in a certain error, so I will leave a memo as a memorandum.
UnicodeDecodeError: '****' codec can't decode byte 0x** in position **:
Looking at this error, I wondered if there was something wrong with the CSV, or if the code below was flawed. But this was not the case.
with open(path, encoding="***")
dir = os.getcwd() + "/" + folder
files = os.listdir(dir)
This code can return the files that exist in a certain folder in list format. I was trying to use this code to handle a large number of JSON and CSV files in list format.
The cause was that files prefixed with., So-called hidden files, were included in the list. For my environment, ".DS_Store" was included in the list.
If you get stuck in a similar error (swamp), it is recommended that you make sure that you have not accidentally read a "file that you do not want to handle" such as a hidden file.
Recommended Posts