使用的是 Python 3

代码:

#!/usr/bin/python
# -*- coding: gbk -*-

# JSON数据导出到csv文件

import json
import pandas

file = open("data//001.txt", "r", encoding="utf-8")
data = file.read()
file.close()

jsonData = json.loads(data)

i = 0
dataList = []
for hitsItem in jsonData['hits']['hits']:
    i = i + 1
    if i <= 10000000:
        source = hitsItem['_source']
        item = {'plate_no': source['plate_no'],
                'tollgate_name3': source['tollgate_name3'],
                'pass_time': source['pass_time']}
        dataList.append(item)

print("数据总数:" + str(len(dataList)))

df = pandas.DataFrame(dataList, columns=['plate_no', 'tollgate_name3', 'pass_time'])

df.to_csv('data//001.csv', index=False, header=True, encoding="utf-8-sig")

print("完成")
View Code

相关文章:

  • 2021-09-17
  • 2021-05-20
  • 2021-11-17
  • 2022-01-11
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-03-26
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案