Serge
Serge

Reputation: 87

unexpected unicode values in dataframe?

I can't find why this is happening. Can i get a justification ?

using pandas in python, if I write in the console:

pd.io.json.read_json('{"rCF":{"values":0.05}}')

I got printed a dataframe that looks like this

        rCF
values  0.05

This if fine.

But if I write in the console:

pd.io.json.read_json('[{"rCF":{"values":0.05}}]')

I got printed a dataframe that looks like this

     rCF
0    {u'values': 0.05}

in particular, why the key is u'values' and not just 'values'

Upvotes: 0

Views: 234

Answers (1)

Alex Martelli
Alex Martelli

Reputation: 881805

json always decodes to Unicode:

>>> import json
>>> json.loads('{"a":"b"}')
{u'a': u'b'}

It's just that in your former case a print or the equivalent somewhere inside pandas is hiding this, as would, e.g:

>>> x = _
>>> for k in x: print k
... 
a

after the above snippet; but when you print (or the like) a container, you get to see the more precise repr of the container's items.

Upvotes: 2

Related Questions