如何将数据写入 python 中的文本文件?

How to write a data to a text file in python?

我很了解 python,我在 Python 中开始了我的第一个代码,但我无法将数据写入文本文件。谁能帮我把我的数据写到文本文件中:

我正在使用 Python 3.4

 In [66]:data
 Out[66]: 
                                  var1         var2
 20:22:49.999985        0.2160       0.1720

open('out.txt', 'w').write(data)

你可以

file = open('filename', 'w');
file.write(data.to_string());    // if data is a pandas.DataFrame object
file.close();