I want to export dataframe with special request.
I want to add string at first row and start exporting dataframe from second row.
# dt
col1 col2
AAA 10
BBB 50
For example, the string I want to add at first row is FIRST
.
The csv
exported data should looks like:
FIRST
col1,col2
AAA,10
BBB,50
Is it possible to do so?
CodePudding user response:
Pandas can export a dataframe as csv to an already open file:
fd = open('file.csv', 'w')
print('FIRST', file=fd)
df.to_csv(fd, index=None)