Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将数据从json文件打印到csv文件_Python_Csv_Python 3.x - Fatal编程技术网

Python 将数据从json文件打印到csv文件

Python 将数据从json文件打印到csv文件,python,csv,python-3.x,Python,Csv,Python 3.x,当我将数据从json文件打印到csv文件时,它不会打印在不同的列中。。 这是我的密码 import json import urllib import csv def main(): f1 = open('tweet-stream.json','r') Outputfile =open('newdata3.csv', 'w') count = 0 for line in f1: d = json.loads(line) lang = d["user"]

当我将数据从json文件打印到csv文件时,它不会打印在不同的列中。。 这是我的密码

import json

import urllib
import csv

def main():

  f1 = open('tweet-stream.json','r')
  Outputfile =open('newdata3.csv', 'w')

  count = 0

  for line in f1:
    d = json.loads(line)
    lang =  d["user"]["lang"]
    status_count = d["user"]["statuses_count"]
    print >>Outputfile,"Language: " + lang + "Status_Count" +str(status_count)


if __name__ == "__main__":
   main()
f1 = json.load(open(tweet-stream.json', 'r'))
fileWriter = csv.writer(file1 , delimiter=",",quotechar='"', quoting=csv.QUOTE_MINIMAL)
for x in f1:
    temp = [x["user"]["lang"],x["user"]["statuses_count"]]
    fileWriter.writerow(temp)
file1.close()