字典追加字典[关闭]

问题描述 投票:-1回答:1
有四个格date macd dif close我想从与时间相对应的几个字典中提取合格元素,然后形成一个新的字典通过两层for循环遍历所有元素

for i in range(10): for j in range(9): if((macd.iloc[i, j] <= 0) & (macd.iloc[i+1, j] >= 0)): data1[j] = {'date':date.iloc[i+1,0],'dif':dif.iloc[i+1,j],'close':close.iloc[i+1, j]} data2[j] = {'date':date.iloc[i , 0],'dif':dif.iloc[i , j],'close':close.iloc[i, j]} today_data[j] = today_data.append(data1[j], ignore_index=True) lastday_data[j] = lastday_data.append(data2[j], ignore_index=True)

我想建立两个字典today_data, lasttoday_data,这些字典按顺序包含选定的元素。但是问题是字典无法追加字典。我该如何解决?
python dictionary append
1个回答
0
投票
dict2.update(dict1) // will merge dict1 to dict2

https://www.programiz.com/python-programming/methods/dictionary/update

© www.soinside.com 2019 - 2024. All rights reserved.