Header not getting written in csv at the time of export from python -
i using python 3.4. exporting results python csv file. headers not getting written. given below piece of code using
with open('c:/twitter_crawl/scoring_tweet.csv', 'r') fp:
with open('scored_tweets.csv', 'w',newline='') op: headers=['processed_tweet','sentiment'] = csv.dictwriter(op,delimiter=',',fieldnames=headers) line in fp.readlines(): sentiment = nbclassifier.classify(extract_features(getfeaturevector(line))) a.writerow({'processed_tweet':line,'sentiment':sentiment})
the file created data populated no headers. can please me out?
thanks in advance!!
to write header, must call csv.dictwriter.writeheader method: writerow write rows...
Comments
Post a Comment