def test_df_col_or_idx_equivalence(df1,
df2,
col=None):
'''check whether two dataframes contain the same elements (but not
necessarily in the same order) in either the indexes or a selected column
inputs
df1, df2
the dataframes to check
col
if not None, test this dataframe column for equivalency, otherwise
test the dataframe indexes
Returns True or False
'''
if not col:
result = all(np.in1d(df1.index, df2.index,
assume_unique=True,
invert=False))
else:
result = all(np.in1d(df1[col], df2[col],
assume_unique=False,
invert=False))
return result
评论列表
文章目录