0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

2つのTBLの差分を比較する (mergeを使って)

Posted at

2つのTBLの差分を比較して相違点を洗い出す。


a1 = pd.read_csv("test.csv")
a2 = pd.read_csv("test2.csv")


a_merge = pd.merge(a1,a2,how="outer",on="カラム1",indicator=True)

a_merge["_merge"].values_counts()

肝はindicatorを使うこと。_mergeカラムができること。
indicatorはどれぐらい紐づいているかを判別するオプションみたいですね。

2つをマージして、_mergeをみると

both , left_only,right_onlyの表示が出てくる。

これにより、左にしかないもの右にしかないものを見ることが可能になる。

最終的に、以下を実行すれば違うところが目に見えてわかるので便利かもしれない。。。

a_merge[a_merge["_merge"] == "left_only"]
a_merge[a_merge["_merge"] == "right_only"]

参考:
https://qiita.com/mk_GF/items/2c47dfed15520d34f7d4

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?