Python, pandas and json_read with utf-8 encoding

Published on 02 November 2015

The pandas library is a fantastic python toolkit to work with data. Recently I needed to read some json files in a pandas dataframe. Usually you can do that easily with the built in method:

import pandas as pd pd.read_json('example.json')

But this method fails, if it encounters utf-8 encoded files. In contrast to the more often used methods read_table and read_csv, read_json does not provide an encoding parameter. To work around this you have to import the codecs module and use the open method:

import codecs import pandas as pd pd.read_json(codecs.open('example.json', 'r', 'utf-8'))