Take the 2-minute tour ×

Use the dframe from pandas module:

df = dframe.resample('t', how = 'sum')

And after that I want to write the data in a new file. I use this:

with open('dframe.txt', 'w') as fout:
   fout.write(df.price1) #it is the first column

But it doesn't work.

share|improve this question
Please elaborate on the "does not work" part. We're not mind readers (yet) ;) Try formulating a question. –  andr Jan 19 '13 at 7:49
add comment

3 Answers

up vote 3 down vote accepted

df.price1 returns a Series. Luckily Series also has a to_csv method similar to the DataFrame's:

Definition: Series.to_csv(self, path, index=True, sep=',', na_rep='',
float_format=None, header=False, index_label=None, mode='w', nanRep=None,

Example usage:

share|improve this answer
add comment


df.to_csv('mydf.txt', sep='\t')
share|improve this answer
add comment

FYI there is also:

  • DataFrame.to_html()
  • DataFrame.to_excel()
  • DataFrame.to_latex()
  • and many others but not for file serialisation

Only needed to use to_excel: the usage is in the method documentation or on http://pandas.pydata.org/pandas-docs/stable/

share|improve this answer
add comment

Your Answer


