Skip to content

Instantly share code, notes, and snippets.

@gdoteof
Last active October 21, 2018 16:02
Show Gist options
  • Save gdoteof/2aa3c8ee264fae68833265f3596883a0 to your computer and use it in GitHub Desktop.
Save gdoteof/2aa3c8ee264fae68833265f3596883a0 to your computer and use it in GitHub Desktop.
An attempt
def expandJson(df, colName):
jsonString = df.iloc[0][colName]
decoded = json.loads(jsonString)
attrs = decoded.keys()
fld = df[colName]
for attr in attrs: df[attr] = json.loads(fld)[attr]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-19-bbe1cebc251e> in <module>
8 for attr in attrs: df[attr] = json.loads(fld)
9
---> 10 expandJson(df_raw,"totals")
<ipython-input-19-bbe1cebc251e> in expandJson(df, colName)
6 attrs = decoded.keys()
7 fld = df[colName]
----> 8 for attr in attrs: df[attr] = json.loads(fld)
9
10 expandJson(df_raw,"totals")
~/anaconda2/envs/fastai/lib/python3.6/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 if not isinstance(s, (bytes, bytearray)):
347 raise TypeError('the JSON object must be str, bytes or bytearray, '
--> 348 'not {!r}'.format(s.__class__.__name__))
349 s = s.decode(detect_encoding(s), 'surrogatepass')
350
TypeError: the JSON object must be str, bytes or bytearray, not 'Series'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment