如果某个列与 csv 文件的第一列匹配,如何在日志文件中获取该列?如果没有匹配,则打印“未检测到”,然后如果匹配:获取日志文件中的某个列。我已经解决这个问题 2 天了,请帮忙
这是我的日志文件结构:完整内容:trendx.log
1537761898 0 1 1 1537733097 1537733098 1537733097 8224 74 215552 06a60c6018a42b1db22e3bf8620861711401c4bb.crdownload TROJ.Win32.TRX.XXPE50FFF026 c:\users\administrator\desktop\downloader\download\ TRENDX 172.20.4.179 Administrator c1f387a6f45414366755b0a1874b36ff9596d8ad AABACACCBIiAgXWACAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= TSPY_HPDYRE.SM;TSPY_GOLROTED.ACS;TROJ_GEN.R021C0FFO15;TROJ_GEN.R021C0DLO15;Ransom_HPCRYPTESLA.SM2;
并采样我的 csv 文件:完整内容:sha1_vsdt.csv
SHA-1,VSDT,
0191a23ee122bdb0c69008971e365ec530bf03f5,MIME 6010-0,
02b809d4edee752d9286677ea30e8a76114aa324,Microsoft RTF 6008-0
0349e0101d8458b6d05860fbee2b4a6d7fa2038d,Adobe Portable Document Format(PDF)
我使用了这个,但我不知道为什么它输出未检测到然后从第 30 行到 552 行开始它不显示任何内容:
import numpy as np
import pandas as pd
import csv
#Log data into dataframe using genfromtxt
logdata = np.genfromtxt("trendx.log",invalid_raise = False,dtype=str, comments=None,usecols=np.arange(0,24))
logframe = pd.DataFrame(logdata)
#Dataframe trimmed to use only SHA1, PRG and IP
df2=(logframe[[10,14,15]]).rename(columns={10:'SHA1', 14: 'PRG',15:'IP'})
#sha1_vsdt data into dataframe using read_csv
df1=pd.read_csv("sha1_vsdt.csv",delimiter=",",error_bad_lines=False,engine = 'python',quoting=3)
#Using merge to compare the two CSV
df = pd.merge(df1, df2, left_on='SHA-1', right_on='SHA1', how='left').replace(np.nan, 'undetected', regex=True)
print(df[['SHA-1','VSDT','PRG','IP']])
拉风的咖菲猫
慕沐林林
相关分类