0

I have a dataframe in pandas as such

Name    Age    Gender
Emily   10     female
Rob     12     male

I want to save a csv file from this dataframe so that it looks like so

Index     ColumnName
0         Name
1         Age
2         Gender

I can't find anything online which tell me how I can do this.

1 Answer 1

3
pd.DataFrame({"ColumnName": df.columns}).to_csv("path/to/file.csv")
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.