Python/Python For Analytics

[Python] pandas를 이용한 IIS log 파싱

Pydole 2019. 8. 30. 20:19

python pandas를 이용한 iis weblog 파싱

 

import pandas as pd

log_field = ['date', 'time', 's-sitename', 's-computername' , 's-ip' , 'cs-method' , 'cs-uri-stem', 'cs-uri-query', 's-port' ,'cs-username',
                   'c-ip', 'cs-version', 'cs-User-Agent', 'cs-Cookie', 'cs-Referer', 'cs-host', 'sc-status', 'sc-substatus', 'sc-win32-status',
                   'sc-bytes', 'cs-bytes', 'time-taken']

df = pd.read_csv('logfile', sep=' ', comment='#', engine='python', names=log_field)
print(df)

0      2018-02-05  01:00:00     W3SVC1  ...      323      160         15
1      2018-02-05  01:00:00     W3SVC1  ...      482      175          0
2      2018-02-05  01:00:00     W3SVC1  ...      297     4231        249
3      2018-02-05  01:00:00     W3SVC1  ...      323      164         15
4      2018-02-05  01:00:00     W3SVC1  ...      744      224         15
...           ...       ...        ...  ...      ...      ...        ...
69791  2018-02-05  01:55:19     W3SVC1  ...      482      175         15
69792  2018-02-05  01:55:19     W3SVC1  ...   119368      197        109
69793  2018-02-05  01:55:19     W3SVC1  ...      323      160         31
69794  2018-02-05  01:55:19     W3SVC1  ...      329     3908         31
69795  2018-02-05  01:55:19     W3SVC1  ...      500      182          0

[69796 rows x 22 columns]