0

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?

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.