0

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'

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
Serge
  • 87
  • 2
  • 10

1 Answers1

2

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.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395