I need to create a pandas series whose elements are each a function of a row from a DataFrame. Specifically the is a 'metadata' column which is a json string and I want a Series of dicts that are the json plus the rest of the columns. Ideally I would want something equivalent to a map method for a dataframe:
df.map(lambda row: json.loads(row.metadata).update({'timestamp':row.timestamp}))
(update is destructive and does not return a new dict but you get the point)
EDIT: You can copy this
metadata timestamp
"{'a':1,'b':2}" 000000001
"{'a':1,'c':2}" 000000002
"{'a':1,'c':2}" 000000003
And load it with
In [8]: import pandas as pd
In [9]: pd.read_clipboard()
Out[9]:
metadata timestamp
0 {'a':1,'b':2} 1
1 {'a':1,'c':2} 2
2 {'a':1,'c':2} 3
The desired result should be a pandas.Series with the contents of this list:
[{"a":1,"b":2,"timestamp":000000001}
{"a":1,"c":2,"timestamp":000000002}
{"a":1,"c":2,"timestamp":000000003}]
pandas.read_clipboard()(test it yourself to check)