for loop-如何在Pandas的列表列中执行VLOOKUP函数?
发布时间:2022-09-02 17:36:49 382
相关标签: # 数据
我有两个df。
data = [['123', ['135', '987']], ['456', ['246', '000', '111']], ['789', ['369']]]
df = pd.DataFrame(data, columns=['case_id', 'case_num']) #create first df
data1 = [[' ', '135'], [' ', '000'], [' ', '369']]
df_target = pd.DataFrame(data1, columns=['case_id', 'case_num']) #create target df
list_of_id = []
for number in df_target['case_num']: #run through the df target's case numbers
temp = []
for list_of_numbers in enumerate(df['case_num']): #run through df's case numbers
if number in list_of_numbers:
temp.append(df.iloc[j]['case_id']) #add the case IDs to the temp list
list_of_id.append(temp) #append and save the relevant case IDs
它完成了它应该做的事情,但数据帧太大了,需要很长时间。我知道有时我不必使用两个“for”循环,那么还有其他方法吗?
编辑:
Expected Output should be that df_target has the corresponding 'case_id'. The code I showed above only put the corresponding 'case_id' in a list.
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报