Skip to content

Instantly share code, notes, and snippets.

@viniroger
Created October 18, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniroger/097de619aa7887f4430057c9bea52a04 to your computer and use it in GitHub Desktop.
Save viniroger/097de619aa7887f4430057c9bea52a04 to your computer and use it in GitHub Desktop.
Save dataframe at file with same width columns
import pandas as pd
df1 = pd.read_csv('input.csv', delimiter=';', header=None)
# Save into fixed columns file
import numpy as np
with open('output.dat', 'w') as ofile:
fmt = '%5d %4d %4d %4d %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f'
np.savetxt(ofile, df1.values, fmt=fmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment