pandas读取大文件json

首先,更换一个64位python(推荐3.6版本63位的Anaconda)和较大内存的工作站。

  • 使用库:
    pandas
    json
  1. 如果json中有中文字符,则以utf-8格式读取为字符串
dataopen = open(path,'r',encoding='utf-8').read()
  1. 键值中有非法控制符号如\n\t则采用strict=False参数读取,将字符串读取为dict字典结构
dataj = json.loads(dataopen,strict=False)

3.适当清洗数据

del dataf['com_id']
del dataf['id']
del dataf['page_url']
  1. 使用pandas库将数据字典转换为DataFrame数据帧格式

  2. 单元键值过长出现with link or location/anchor > 255 characters since it exceeds Excel's limit for URLS force_unicode(url))问题,使用ExcelWriter设置不要将strings转换成urls

writer = pd.ExcelWriter(r'WebHireExcel.xlsx', engine='xlsxwriter',options={'strings_to_urls': False})
  1. 再次转换,参数设置为ExcelWriter转换器
dataf.to_excel(writer)
pandas读取大文件json_第1张图片

你可能感兴趣的:(pandas读取大文件json)