Combine two arrays data using inner join

2024/10/2 18:32:09

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],...
]

I mean, just combine those lines with the same date column.

Just for clarification, I don't need those lines which not appear in both array, just drop them.

Answer

Organize your data differently (you can easily convert what you already have to two dicts):

d1 = { '2011-10-10': [1, 1],'2007-08-09': [5, 3]}
d2 = { '2011-10-10': [3, 4],'2007-09-05': [1, 1]}

Then:

d3 = { k : d1[k] + d2[k] for k in d1 if k in d2 }
https://en.xdnf.cn/q/70824.html

Related Q&A

How to change fontsize of individual legend entries in pyplot?

What Im trying to do is control the fontsize of individual entries in a legend in pyplot. That is, I want the first entry to be one size, and the second entry to be another. This was my attempt at a so…

Split array into equal sized windows [duplicate]

This question already has answers here:Sliding window of M-by-N shape numpy.ndarray(8 answers)Closed 10 months ago.I am trying to split an numpy.array of length 40 into smaller, equal-sized numpy.array…

Is there a way to send a click event to a window in the background in python?

So Im trying to build a bot to automate some actions in a mobile game that Im running on my pc through Bluestacks.My program takes a screenshot of the window, looks for certain button templates in the …

how to store an image into redis using python / PIL

Im using python and the Image module(PIL) to process images.I want to store the raw bits stream of the image object to redis so that others can directly read the images from redis using nginx & htt…

Delete OCR word from Image (OpenCV,Python)

So, from what I can begin..I am working with OCR. The script works pretty well for what I need. It detects the words with an accuracy which for me is ok.This is the result: 100% accuracy with attached …

pandas.to_datetime inconsistent time string format

I am attempting to convert the index of a pandas.DataFrame from string format to a datetime index, using pandas.to_datetime().Import pandas:In [1]: import pandas as pdIn [2]: pd.__version__ Out[2]: 0.1…

Python NLTK WUP Similarity Score not unity for exact same word

Simple code like follows gives out similarity score of 0.75 for both cases. As you can see both the words are the exact same. To avoid any confusion I also compared a word with itself. The score refuse…

SystemExit: 2 error when calling parse_args() in iPython Notebook

Im learning to use Python and scikit-learn and executed the following block of codes (originally from http://scikit-learn.org/stable/auto_examples/document_classification_20newsgroups.html#example-docu…

How to convert numpy datetime64 [ns] to python datetime?

I need to convert dates from pandas frame values in the separate function:def myfunc(lat, lon, when):ts = (when - np.datetime64(1970-01-01T00:00:00Z,s)) / np.timedelta64(1, s)date = datetime.datetime.u…

how to remove a back slash from a JSON file

I want to create a json file like this:{"946705035":4,"946706692":4 ...}I am taking a column that only contains Unix Timestamp and group them.result = data[Last_Modified_Date_unixti…