df.to_csv
accepts a file object. So you can open a file in a
mode, write you comments and pass it to the dataframe to_csv function.
For example:
In [36]: df = pd.DataFrame({'a':[1,2,3], 'b':[1,2,3]})
In [37]: f = open('foo', 'a')
In [38]: f.write('# My awesome comment
')
In [39]: f.write('# Here is another one
')
In [40]: df.to_csv(f)
In [41]: f.close()
In [42]: more foo
# My awesome comment
# Here is another one
,a,b
0,1,1
1,2,2
2,3,3
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…