比较两个数据框列

时间:2019-03-07 11:08:51

标签: python-3.x dataframe

我有一个如下数据框。

web_1_c758cf247b33 | xx.xx.xx.xx - - [21/Mar/2019:12:29:48 +0000] "GET / HTTP/1.1" 200 1811 "https://tcms.xx:8443/runs/search/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184167 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058] Internal Server Error: /plans/new/
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184214 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058] Traceback (most recent call last):
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184219 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184224 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     response = get_response(request)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184228 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184233 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     response = self.process_exception_by_middleware(e, request)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184237 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184241 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184245 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/views/generic/base.py", line 68, in view
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184252 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     return self.dispatch(request, *args, **kwargs)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184256 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184260 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     return bound_method(*args, **kwargs)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184265 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184269 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     return view_func(request, *args, **kwargs)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184273 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184277 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     return handler(request, *args, **kwargs)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184281 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/tcms/testplans/views.py", line 63, in get
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184285 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     return render(request, self.template_name, context_data)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184289 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/shortcuts.py", line 36, in render
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184294 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     content = loader.render_to_string(template_name, context, request, using=using)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184298 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/template/loader.py", line 61, in render_to_string
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184302 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     template = get_template(template_name, using=using)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184306 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]   File "/venv/lib64/python3.6/site-packages/django/template/loader.py", line 19, in get_template
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184310 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]     raise TemplateDoesNotExist(template_name, chain=chain)
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184316 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058] django.template.exceptions.TemplateDoesNotExist: testplans/mutable.html
web_1_c758cf247b33 | [Thu Mar 21 12:29:56.184324 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64058]
web_1_c758cf247b33 | xx.xx.xx.xx - - [21/Mar/2019:12:29:56 +0000] "GET /plans/new/ HTTP/1.1" 500 109021 "https://tcms.xx:8443/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
web_1_c758cf247b33 | xx.xx.xx.xx - - [21/Mar/2019:12:30:17 +0000] "-" 408 - "-" "-"
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.334989 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099] Internal Server Error: /plans/search/
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335022 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099] Traceback (most recent call last):
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335027 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335032 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     response = get_response(request)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335036 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335041 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     response = self.process_exception_by_middleware(e, request)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335045 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335050 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335054 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335062 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     return func(request, *args, **kwargs)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335066 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/tcms/testplans/views.py", line 169, in search
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335071 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     return render(request, 'testplans/search.html', context_data)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335075 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/django/shortcuts.py", line 36, in render
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335079 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     content = loader.render_to_string(template_name, context, request, using=using)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335083 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/django/template/loader.py", line 61, in render_to_string
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335088 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     template = get_template(template_name, using=using)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335093 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]   File "/venv/lib64/python3.6/site-packages/django/template/loader.py", line 19, in get_template
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335097 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]     raise TemplateDoesNotExist(template_name, chain=chain)
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335103 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099] django.template.exceptions.TemplateDoesNotExist: testplans/search.html
web_1_c758cf247b33 | [Thu Mar 21 12:30:23.335111 2019] [wsgi:error] [pid 11] [remote xx.xx.xx.xx:64099]
web_1_c758cf247b33 | xx.xx.xx.xx - - [21/Mar/2019:12:30:23 +0000] "GET /plans/search/ HTTP/1.1" 500 95055 "https://tcms.xx:8443/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"

我想将A列中的每个值与B列中的所有值进行比较,如果它至少出现一次,则返回True;如果像下面的C列中不存在,则返回False

=arrayformula(if(row(C:C)=1;"Column 3";A:A))

我尝试使用 filter(函数,可迭代),但收到以下错误。

A  B
1  2
2  1
3  4

任何其他想法将不胜感激。

1 个答案:

答案 0 :(得分:0)

不清楚在什么条件下返回True或False的逻辑,无论如何,我们假设您要为b中出现的a中的每个值返回True:

A = df['A'].tolist()
B = df['B'].tolist()
C = [(a in B) for a in A]