0
이것은 간단한 질문 일 수 있습니다. 하지만 여기서 무슨 일이 일어나고 있는지를 파악하지 않고 많은 시간을 낭비했습니다. 리소스 확장을 기반으로 웹 로그 파일에서 HTTP 요청을 분류하려고합니다. 다음은 내가 시도한 것입니다.목록에있는 값을 기반으로 Pandas DataFrame 삽입 열
imgstr = ['.png','.gif','.jpeg','.jpg']
docstr = [ '.pdf','.ppt','.doc' ]
webstr = ['.html','.htm', '.asp', '.jsp', '.php', '.cgi', '.js','.css']
compressed = ['zip', 'rar', 'gzip', 'tar', 'gz', '7z']
def rtype(b):
if any(x in b for x in imgstr):
return 'A'
elif any(x in b for x in docstr):
return 'B'
elif 'favicon.ico'in b:
return 'C'
elif 'robots.txt'in b:
return 'D'
elif 'GET/HTTP/1.1' in b:
return 'E'
elif any(x in b for x in webstr):
return 'F'
elif any(x in b for x in compressed):
return 'G'
else:
return 'H'
df2['result'] = df2.Request.apply(rtype)
그러나 df2['result']
은 'A'
입니까? df2.Request
의 데이터 형식은 Object
입니다. 나는 df2['Referer'] = df2['Referer'].astype(str)
으로 변경하려고 시도했다. 그래도 dtype은 Object
입니다. 다음은 첫 번째 10 df2.Request
입니다.
0,GET /index.php?lang=ta HTTP/1.1
1,GET /index.php?limitstart=25&lang=en HTTP/1.1
2,GET /index.php/ta/component/content/article/43 HTTP/1.1
3,GET /index.php/ta/component/content/article/39-test HTTP/1.1
4,GET /robots.txt HTTP/1.1
5,GET /robots.txt HTTP/1.1
6,GET /index.php/en/computer-security-feeds/15-computer-security/2-us-cert-cyber-security-alerts HTTP/1.1
7,GET /index.php/component/content/article/10-tips/59-use-firefox-more-safe HTTP/1.1
8,GET /robots.txt HTTP/1.1
9,GET /onlinerenew/ HTTP/1.1