简体   繁体   English

循环遍历 2 个数据帧的更好方法

[英]A better way to loop through 2 Dataframes

I have 2 Dataframes.我有 2 个数据框。 i am trying to find corresponding row values based on filter values.我正在尝试根据过滤器值查找相应的行值。 At the end, i want to add some columns in df2 to df1.最后,我想将 df2 中的一些列添加到 df1。 The problem with the example below is that it is nor efficient when dealing with large dataset.下面这个例子的问题是它在处理大型数据集时效率也不高。

selected_rows = pd.Dataframe()
         for i, rowi in df1.iterrows():
              for j, rowj in df2.iterrows():
                if (rowi['Customer'] == rowj['Customer']) & (rowi['CaseID'] == rowj['CaseID']):
                    rowi['Resolution'] = rowj['Resolution']
                    rowi['Diagnostic'] = rowj['Diagnostic']
                    selected_rows = selected_rows.append(rowi)

This helped me: link .这对我有帮助:链接 I use an approach like this instead of using iterrows()我使用这样的方法而不是使用iterrows()

for i in df.index:
    value = df._get_value(i, column)

which seems to be faster, but I think there are multiple approaches to get even faster.这似乎更快,但我认为有多种方法可以变得更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM