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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -