python - UnicodeDecodeError in a pandas dataframe created from JSON file -
i have piece of code running on ipython notebook downloads json file , parses content pandas df. however, if try inspect df, encoding error.
output = r.json() columns_map = {'/people/person/date_of_birth': 'birth_date', '/people/person/place_of_birth': 'birth_place', '/people/person/gender': 'gender'} df = pd.dataframe(output['result']) df.rename(columns=columns_map, inplace=true) df.to_csv('file.csv',encoding='utf-8')
i can create csv df w/o problems, if type
df
to inspect df inside ipython notebook, this:
unicodedecodeerror: 'ascii' codec can't decode byte 0xc3 in position 1894: ordinal not in range(128)
can help?
after research, found problem python version < 3.0. weird reason, quick fix import sys , relaod sys. worked me:
import sys reload(sys) sys.setdefaultencoding('utf8')
Comments
Post a Comment