Compare whether 2 dataframes are the same in Julia

Viewed 318

Imagine I have 2 data frames and they are from 2 databases. The 2 data frames should be exactly the same and they have both string and numbers. Is there a way to compare whether the 2 data frames are the same and list records that are different?

enter image description here

1 Answers

It is still not clear what input you have and what output you want. In my answer I assume you use DataFrames.jl and you want a list of rows that differ.

Assume that the data frames are df1 and df2.

  1. How to tell if two data frames are the same:
df1 == df2 # if data frames do not have missing values in them

isequal(df1, df2) # if data frames do have missing values in them

(the reason for the difference is that Julia is in general missing-sensitive)

  1. If they are not equal then first check if they have equal column names:
names(df1) == names(df2)
  1. If column names are indeed equal here is a way to get a Bool vector of mismatched rows:
.!=(eachrow(df1), eachrow(df2)) # no missings
.!isequal.(eachrow(df1), eachrow(df2)) # with missings

(there are other options than this one that might be faster, but this is simplest)

Related