stat157 / recent-quakes

Stat 157 Homework 2 due on Monday 2013-10-21 at 11:59pm
0 stars 20 forks source link

Unicode from USGS website #5

Closed tandrasfay closed 10 years ago

tandrasfay commented 10 years ago

I was able to successfully read the data into python using json.loads, but after printing, the data appear to be in unicode as everything has a u' in front of it: "u'geometry': {u'type': u'Point', u'coordinates'" for example. This leads to a problem trying to extract elements because I keep getting these types of attribute errors. AttributeError: 'unicode' object has no attribute 'iteritems'

Has anyone else had this problem? If so, how did you work around it?

teresita commented 10 years ago

I've been having trouble with this too and the JSON documentation isn't very helpful, so I just did

sudo pip install --upgrade pandas

to upgrade my version of pandas to be able to use the pandas read_json function. hoping that helps.

kqdtran commented 10 years ago

@teresita I'm curious about how you got read_json to work? :o I've been playing around with it to no avail so far. Edit: oops, I meant read_json with the error that @reenashah mentioned in https://github.com/stat157/recent-quakes/issues/3, not installation error.

@tandrasfay I think you can access the dictionary items without worrying about unicode. For example, if your dictionary is quakes, you can do quakes['geometry']. It seems to work for me without any unicode error, so keep us posted :-)

GalaxyNight-day commented 10 years ago

Try

sudo apt-get install python-pandas

it worked for me

kqdtran commented 10 years ago

Oops, I meant the ValueError: arrays must all be same length with read_json, not installation error :D. Edited my post above.

teresita commented 10 years ago

@kqdtran yeah, I ran into that error too, right after posting..

I'm starting to think that a data frame isn't the best way to represent these data. Maybe there's another way to parse it to extract only the parameters that we're interested in..

aculich commented 10 years ago

The answer to everything here can be found in Issue #8 and we covered this in Office Hours, as well, so i am going to close this now.

@teresita Glad you found and shared a solution to upgrade pandas since the read_json function was missing from the version we were using.