python - Multiple pandas.dataframe to one csv file -


i have multiple pandas dataframes, , hope write them 1 csv file. straightforward way?

for example, following 4 dataframes,

enter image description here

how can create below csv?

enter image description here

note dataframes have same dimensions.

a straightforward way concat pairs horizontally, concat results vertically, , write out using to_csv:

 import pandas pd   pd.concat([     pd.concat([df1, df2], axis=1),     pd.concat([df3, df4], axis=1)]).to_csv('foo.csv') 

a possibly more memory-conserving way write piecemeal:

with open('foo.csv', 'w') f:      pd.concat([df1, df2], axis=1)].to_csv(f) open('foo.csv', 'a') f:      pd.concat([df3, df4], axis=1)].to_csv(f, header=false) 

omitting headers=false repeat headers.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -