0

I have some data I want to store in a csv file:

result  |  DataFrame  |  (90422, 17)  |  Column names: age, job, marital

However, my script only creates an empty csv file. How can I get it to actually output the data that I want?

for row in result:
    counter[row[0]] += 1
writer = csv.writer(open('file.csv', 'w'))
for row in result:
    if counter[row[0]] >= 0:
        writer.writerows(row)
ayhan
  • 70,170
  • 20
  • 182
  • 203
wwang
  • 19
  • 1
  • 3
  • 1
    please code data and code here in the question itself as text – e4c5 May 02 '16 at 05:12
  • refer http://stackoverflow.com/questions/3348460/csv-file-written-with-python-has-blank-lines-between-each-row – Riken Shah May 02 '16 at 05:14
  • 2
    DataFrame has a `to_csv` method so you can just use result.to_csv(filename) http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html – ayhan May 02 '16 at 05:15

1 Answers1

1

use the to_csv method integrated in the pandas library

my_dataframe.to_csv('name_of_file', sep=',')
Diego Aguado
  • 1,604
  • 18
  • 36