0

当我将数据从我的 json 文件打印到 csv 文件时,它没有打印在 diff 列中。这是我的代码

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()
4

1 回答 1

0
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()
于 2013-04-05T13:55:44.397 回答