str对象没有属性日错误

时间:2017-12-31 14:36:01

标签: python csv opencsv

这是我的代码。不确定是什么问题。我在哪里获取CSV文件的day属性?是否需要在过滤中添加?

import apache_log_parser

from pandas import DataFrame


parser = apache_log_parser.make_parser('%h %l %u %t "%r" %>s')

data = {'day': [],
        'time': []}

with open('coursework.csv') as in_f:

    reader = DictReader(in_f)
    for line in reader:
        identifier = '%s_%s' % (line['time_received_isoformat'], line['remote_host'])

        data['day'].append(line['time_received_isoformat'].day)
        if 'search' in line['request_url_path']:
            data['category'].append('search')
        elif 'browse' in line['request_url_path']:
            data['category'].append('browse')
        elif 'add-to-cart' in line['request_url_path'] or 'remove-from-cart' in line['request_url_path']:
            data['category'].append('cart')
        elif 'book' in line['request_url_path']:
            data['category'].append('item')
        elif line['request_url_path'] == '/baseline/':
            data['category'].append('baseline')
        elif line['request_url_path'] == '/explore/' or line['request_url_path'] =='/review/':
            data['category'].append('modern')
        else:
            print(line['request_url_path'])
print(data['day'])

0 个答案:

没有答案