Pandas aggregation functions return TypeError: Object of type int64 is not JSON serializable.
Here is the dataframe:
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
df
Out[47]:
col1 col2
0 1 3
1 2 4
Here is how I am aggregating the column:
sum_col = df.col1.sum()
sum_col
Out[49]: 3
But as soon as I do json.dumps() it gives a type error:
data = json.dumps(sum_col)
data
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-50-5d4b966e64cc> in <module>
----> 1 data = json.dumps(sum_col)
2 data
TypeError: Object of type int64 is not JSON serializable