How to split an excel file that contains 5000 columns into 5000 single files?

Question:

I have a database in form of .xlsx, which contains 5000 columns. My goal is to separate it into 5000 single files in order to train them for a neural network.
How I can do it in Python??

Asked By: Luckie One

||

Answers:

There you go:

import pandas as pd
df = pd.read_excel('data.xlsx')
cols = df.columns

for col in cols:
    df1 = df[col]
    df1.to_excel(str(col) + '.xlsx', index = False)
Answered By: Chadee Fouad
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.