使用内部联接合并两个数组的数据 [英] Combine two array's data using inner join
本文介绍了使用内部联接合并两个数组的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数组中有两个数据集:
I've two data sets in array:
arr1 = [
['2011-10-10', 1, 1],
['2007-08-09', 5, 3],
...
]
arr2 = [
['2011-10-10', 3, 4],
['2007-09-05', 1, 1],
...
]
我想像这样将它们组合成一个数组:
I want to combine them into one array like this:
arr3 = [
['2011-10-10', 1, 1, 3, 4],
...
]
我的意思是,只需将这些行与相同的date
列组合即可.
I mean, just combine those lines with the same date
column.
谢谢大家,为澄清起见,我不需要那些不在两个数组中都出现的行,只需将它们放下即可.
Thanks everyone, Just for clarification, I don't need those lines which not appear in both array, just drop them.
推荐答案
以不同的方式组织数据(您可以轻松将已有的内容转换为两个dict
):
Organize your data differently (you can easily convert what you already have to two dict
s):
d1 = { '2011-10-10': [1, 1],
'2007-08-09': [5, 3]
}
d2 = { '2011-10-10': [3, 4],
'2007-09-05': [1, 1]
}
然后:
d3 = { k : d1[k] + d2[k] for k in d1 if k in d2 }
这篇关于使用内部联接合并两个数组的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文