python - Only outputting a few lines into a text file, instead of all of them -


i've made python script grabs information .csv archive, , outputs text file list. original csv file has on 200,000 fields input , output from, yet when run program outputs 36 .txt file.

here's code:

import csv open('originalfile.csv', 'r') csvfile:     emailreader = csv.reader(csvfile)     f = open('text.txt', 'a')     row in emailreader:         f.write(row[1] + "\n") 

and text file lists 36 strings. how can fix this? maybe original csv file big?

after many comments, original problem encoding of characters in csv file. if specify encoding in pandas read fine.

any time dealing csv file (or excel, sql or r) use pandas dataframes this. syntax shorter , easier know going on.

import pandas pd csvframe = pd.read_csv('originalfile.csv', encoding='utf-8') open('text.txt', 'a') output:     # think wanted 2nd column each row     output.write('\n'.join(csvframe.ix[:,1].values))     # ix index , : rows , 1 first column 

Comments