Python write 2 lists and Pandas DataFrames to csv/excel sequentially -


i have these python lists , pandas dataframes:

list_1 = ['intro line here - record of method function:'] list_2 = ['record of local minimum follows:']  print df_1    col_a    col_b   3.4443    1.443  10.8876    11.99  print df2 trial_1  trial_2  trial_3     1.1     1.49    775.9    11.5     9.57     87.3  384.61   77.964     63.7   12.49    0.156      1.9  112.11   11.847    178.3 

here want in output csv or excel file - either csv or excel work me:

intro line here - record of method function:    col_a    col_b   3.4443    1.443  10.8876    11.99 record of local minimum follows: trial_1  trial_2  trial_3     1.1     1.49    775.9    11.5     9.57     87.3  384.61   77.964     63.7   12.49    0.156      1.9  112.11   11.847    178.3 

is there way write list, pandas, list, pandas in order csv or excel file?

pd.to_csv() accepts file handle input, not file name. can open file handle , write multiple files it. here's example:

from __future__ import print_function  open('output.csv', 'w') handle:     line in list_1:         print(line, handle)     df1.to_csv(handle, index=false)     line in list_2:         print(line, handle)     df2.to_csv(handle, index=false) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -