test2.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. import csv
  3. import json
  4. if __name__ == '__main__':
  5. # 读取CSV文件
  6. csv_file = r'device_monitor_80.csv' # 替换成你的CSV文件路径
  7. json_list_8 = []
  8. json_list_9 = []
  9. # 读取CSV文件,并提取第8列和第9列的JSON字段
  10. with open(csv_file, 'r') as file:
  11. reader = csv.reader(file)
  12. next(reader) # 跳过标题行
  13. for row in reader:
  14. json_data_8 = json.loads(row[7]) # 第8列的索引为7
  15. json_data_9 = json.loads(row[8]) # 第9列的索引为8
  16. for item in json_data_8:
  17. if 'record' in item['name']:
  18. json_list_8.append(item)
  19. for item in json_data_9:
  20. if 'record' in item['name']:
  21. json_list_9.append(item)
  22. # 打印列表中的所有record字段的值
  23. print("Json List from column 8:")
  24. for record in json_list_8:
  25. print(record)
  26. print("\nJson List from column 9:")
  27. for record in json_list_9:
  28. print(record)