fran-py-

json转化为csv文件打开时,中文乱码

三种方法:

  • 法一

用笔记本打开csv文件,在笔记本中选择“文件”-->“另存为”。设置编码类型为‘utf-8\'

  • 法二

在打开的excel页面中,选择“文件”菜单-->选项-->语言设置为简体中文

  •  法三

1.数据-->从文本

2.依此设置。文件格式设置为  “无(常规)”

 

附json->csv代码

import csv
import json

with open(\'\'\'d:/python/爬虫/txt文件/豆瓣电影top_250.txt\'\'\',\'r\',encoding=\'utf-8\') as f:
       fieldnames=\'\'\'[\'index\',\'name\',\'DaA\',\'score\',\'quote\']\'\'\'
       items=f.readlines()
       content=[]
       for item in items:
           content.append(\'\'\'eval(item.strip())\'\'\')
       
with open(\'\'\'d:/python/爬虫/txt文件/豆瓣电影top_250.csv\'\'\',\'a\',encoding=\'utf-8\',newline=\'\') as ff:
    writer=csv.DictWriter(ff,fieldnames=fieldnames)
    writer.writeheader()
    writer.writerows(content)

 

分类:

技术点:

相关文章:

  • 2021-09-06
  • 2022-02-09
  • 2022-12-23
  • 2021-05-14
  • 2021-12-01
  • 2021-11-19
猜你喜欢
  • 2022-01-28
  • 2021-09-28
  • 2022-12-23
  • 2021-08-17
  • 2021-12-24
  • 2021-12-22
  • 2021-12-02
相关资源
相似解决方案