I am trying to combine 2 columns into my dataframe using a new column which is of type JSON. To do so i have used itertuples() but it is taking a lot of time can anyone suggest me a better approch, here is the data mentioned below:
fn = ('Mike', 'Dorothee')
dob = ('1985-08-07', '1987-01-33')
data = ({'rank':'5', 'subject':'science'}, {'rank':'1', 'subject':'arts'})
df = pd.DataFrame(list(zip(fn, dob, data)), columns =['fn', 'dob', 'data'])
for row in df.itertuples():
df.loc[row.Index, 'result'] = str(dict([(row.dob, row.data)]))
+----------+------------+-------------------------------------+-----------------------------------------------------+
| fn | dob | data | result |
|----------+------------+-------------------------------------+-----------------------------------------------------|
| Mike | 1985-08-07 | {'rank': '5', 'subject': 'science'} | {'1985-08-07': {'rank': '5', 'subject': 'science'}} |
| Dorothee | 1987-01-33 | {'rank': '1', 'subject': 'arts'} | {'1987-01-33': {'rank': '1', 'subject': 'arts'}} |
+----------+------------+-------------------------------------+-----------------------------------------------------+
Select the correct answer from above options