Python Forum
Convert Excel to .txt - Need each excel row to be separate .txt file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Convert Excel to .txt - Need each excel row to be separate .txt file (/thread-23510.html)



Convert Excel to .txt - Need each excel row to be separate .txt file - cowboykevin05 - Jan-03-2020

Disclaimer: total python newb here

I have an Excel file with thousands of rows & 10 columns (with header as row 1).

I need each row (excluding header) to be saved as an individual (tab delimited) .txt file.

Column "A" from each row of the excel file needs to be the file name for each .txt file. The remaining columns need to be the (tab delimited) text within each file.

Example (below) of what I have and what I need... I did this manually for 1 row... but I have thousands of rows. Anybody know where I can find python script to execute this? Please and thank you!

İmage

İmage


Sorry, my first post here... I didn't realize I couldn't add images or edit my post. But I believe my description was clear.


RE: Convert Excel to .txt - Need each excel row to be separate .txt file - perfringo - Jan-03-2020

If I would face this task I would use pandas.

Something like that:
- read Excel file with pandas.read_excel
- iterate rows using pandas.DataFrame.iterrows
- write row to file using pandas.Series.to_csv setting sep as '\t'.


RE: Convert Excel to .txt - Need each excel row to be separate .txt file - Larz60+ - Jan-03-2020

agree with perfringo Pandas is the way to go. A bit of a learning curve, but well worth it.
Lots of tutorials on YouTube