0

i have a big csv file which i cannot open in excel, but somehow I need to sort it further in excel and for this i only need the column headers of my frame, so far i got with a pandas dataframe:

cols = df.columns.tolist()

which leads to a long list of column names:

['ID',
 'ABUNG KZ',
 'ABSTIMMKS',
 'BETR ABWEBUEHR',
 'BETR ABWITEN',
 'AGR ',
 'ANSCH',
 'ANSCHRIFT',
 ...
]

How can I write this list into a excel file, that I have this in one column, all column names in a diffferent row so that it looks like (in excel):

Names
ID
ABUNG KZ
...

1 Answer 1

2

Try the following code:

cols = df.columns.tolist()

data = {'Names': cols} 

df2 = pd.DataFrame(data)
df2.to_excel('df_excel.xlsx', index=False)

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.