2
これはしばらく私を悩ませていました。どうすれば=INDEX(A:A,MATCH(E1&F1,B:B&C:C,0))
をPythonで実現できますか?これが見つからなければ、エラーを返します。はパンダのインデックスマッチに秀でています
だから私はpd.merge_asof
でプレイし始めました。しかし、いずれにしてもエラーを返すだけです。
df_3 = pd.merge_asof(df_1, df_2, on=['x', 'y'], allow_exact_matches=False)
がエラーを与える:
pandas.tools.merge.MergeError: can only asof on a key for left
編集:
import pandas as pd
df_1 = pd.DataFrame({'x': ['1', '1', '2', '2', '3', '3', '4', '5', '5', '5'],
'y': ['smth1', 'smth2', 'smth1', 'smth2', 'smth1', 'smth2', 'smth1', 'smth1', 'smth2', 'smth3']})
df_2 = pd.DataFrame({'x': ['1', '2', '2', '3', '4', '5', '5'],
'y': ['smth1','smth1','smth2','smth3','smth1','smth1','smth3'],
'z': ['other1','other1','other2','other3','other1','other1','other3',]})
は、だから、私は単純に上記の式を使用してExcelでこれを行うと、このような何かを得ることができるサンプル、です:
x y z
1 smth1 other1
1 smth2 #NA
2 smth1 other1
2 smth2 other2
3 smth1 #NA
3 smth2 #NA
4 smth1 other1
5 smth1 other1
5 smth2 #NA
5 smth3 other3
パンダでExcelのINDEX MATCH
公式を達成するための簡単な方法は?
あなたはいくつかのサンプルの入力データを掲示し、結果を期待することはできますか? –
@ScottBoston確かに、私に瞬間を与えてください:-) – destinychoice
@ScottBoston私はサンプルで質問を更新しました。遅れて申し訳ありません、持ち去られました。 – destinychoice