in Education by
consider the two dataframes df1 and df2 df1 = pd.DataFrame(np.zeros((6, 6)), list('abcdef'), list('abcdef'), dtype=int) df1.iloc[2:4, 2:4] = np.array([[1, 2], [3, 4]]) df1 df2 = pd.DataFrame(np.array([[1, 2], [3, 4]]), list('CD'), list('CD'), dtype=int) df2 It's clear that df2 is in df1. How do I test for this in general? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Assuming the dataframes contain 0's and 1s only, you can use 2D convolution and look if any element in the convoluted output is equal to the number of elements in df2 - from scipy.signal import convolve2d out = (convolve2d(df1,df2)==df2.size).any() For a generic case, let me use skimage module and this smart solution - from skimage.util import view_as_windows as viewW out = ((viewW(df1.values, df2.shape) == df2.values).all(axis=(2,3))).any() This is basically a template-matching problem and it has been discussed and we have gotten really efficient solutions under this post : How can I check if one two-dimensional NumPy array contains a specific pattern of values inside it?. That post also gives us the indices of all places in df1 where df2 could be located.

Related questions

0 votes
    Write a c program to find largest and smallest among all elements of 2-d array. Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    2. A………… is a Panda data structure that represents a 2 D array like object (1 Point) Series DataFrame dictionary Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    Create a two 2-D array. Plot it using matplotlib...
asked Apr 24, 2021 in Technology by JackTerrance
0 votes
    I am attempting to solve a problem where if the elements in one array are squared, and all of the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    How do you check for an empty (zero Element) array?...
asked Apr 24, 2021 in Technology by JackTerrance
0 votes
    If a giraffe has two eyes, a monkey has two eyes, and an elephant has two eyes, how many eyes do we have? A) 3 B) 4 C) 1 D) 2...
asked Feb 10, 2021 in Education by JackTerrance
0 votes
    I have an array that has multiple numbers in it. I want the function to return another array of maximum 3 ... { dartsToFinishArrTotal += dartsToFinishArr[n]; } } if (output...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have an array that has multiple numbers in it. I want the function to return another array of maximum 3 ... { dartsToFinishArrTotal += dartsToFinishArr[n]; } } if (output...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Arrange in order- A. running unit test B. running static code check C. check for code D. Build Package...
asked Mar 7, 2021 in Technology by JackTerrance
0 votes
0 votes
0 votes
    A card is drawn from a pack, the card is replaced & the pack shuffled. If this is done 6 times, the ... co-prime natural numbers). Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
...