123456789101112131415161718192021222324252627282930313233 |
- # -*- coding: utf-8 -*-
- import csv
- import json
- if __name__ == '__main__':
- # 读取CSV文件
- csv_file = r'device_monitor_80.csv' # 替换成你的CSV文件路径
- json_list_8 = []
- json_list_9 = []
- # 读取CSV文件,并提取第8列和第9列的JSON字段
- with open(csv_file, 'r') as file:
- reader = csv.reader(file)
- next(reader) # 跳过标题行
- for row in reader:
- json_data_8 = json.loads(row[7]) # 第8列的索引为7
- json_data_9 = json.loads(row[8]) # 第9列的索引为8
- for item in json_data_8:
- if 'record' in item['name']:
- json_list_8.append(item)
- for item in json_data_9:
- if 'record' in item['name']:
- json_list_9.append(item)
- # 打印列表中的所有record字段的值
- print("Json List from column 8:")
- for record in json_list_8:
- print(record)
- print("\nJson List from column 9:")
- for record in json_list_9:
- print(record)
|