I have a txt file that looks like this:
category test_1
aaa.com; test info - tw
bbb.com; test info - al
category test_2
ccc.com; test info - al
ddd.com; test info - tw
eee.com; test info - tw
category test_3
fff.com; test info - tw
ggg.com; test info - al
hhh.com; test info - tw
iii.com; test info - al
I need help creating a Python script that pulls a portion of the txt file and exports it to an excel file. For example, if I want to export the entries in category 'test_1', the script would produce the following output in an excel file.
| A. | B. | C. |
---------------------------------------
1. | aaa.com | test info - tw | |
---------------------------------------
2. | bbb.com | test info - al | |
---------------------------------------
3. | | | |
I have tried to use the code below
My txt file is saved on my desktop as autotest.txt
import pandas as pd
df = pd.read_csv(‘C:\Users\A12345\Desktop\autotest.txt’)
df.to_excel(‘output.xlsx’, ‘Sheet1’)
When I run this code, it doesn’t create an excel file. I’ve also tried to add an excel file named ‘output.xlsx’ on my desktop and when I ran the script it didn’t add the text to the excel file either.