python - How to change a .csv file to .dat file using pandas? -
for example, csv file looks this: csv content. how change .dat file using '|':
a 1|b 2|c 3|d 4|...
2|b 3|c 4|d 5|...
3|b 4|c 5|d 6|...
...
consider dataframe df
df = pd.dataframe([ [1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6] ], columns=list('abcd')) b c d 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6
iiuc
df.astype(str).radd( df.columns.to_series() + ' ' ).to_csv('test.data', header=none, index=none, sep='|')
cat test.data 1|b 2|c 3|d 4 2|b 3|c 4|d 5 3|b 4|c 5|d 6
Comments
Post a Comment