我正在做一些我知道我不該做的事情。我內做一個for循環迴路(聽起來更恐怖,因爲我把它寫下來。)基本上,我想要做的,從理論上說,使用兩個dataframes是這樣的:pandas iterrows()兩個數據框
for index, row in df_2.iterrows():
for index_1, row_1 in df_1.iterrows():
if row['column_1'] == row_1['column_1'] and row['column_2'] == row_1['column_2'] and row['column_3'] == row_1['column_2']:
row['column_4'] = row_1['column_4']
必須有一種(更好的)方式來做這樣的事情。請幫忙!
您可以在這些列上進行內部連接,然後您將得到一個包含所有所需行的新df。迭代比如果你喜歡。 –
另一個複雜的是我可能需要做一些模糊的字符串匹配(列有錯別字)。在這種情況下,內連接不適合我。 –