I have a text file that looks like this
Apple TreeTwo
Banana TreeOne
Juice TreeOne
Pineapple TreeThree
Berries TreeThree
How can I select the rows with the same Tree name and put them in separate files like below in python
file1.txt
Banana TreeOne
Juice TreeOne
file2.txt
Apple TreeTwo
file3.txt
Pineapple
Berries
I've tried using this "https://stackoverflow.com/questions/72065988/how-to-select-all-rows-with-the-same-name-but-different-values-in-python" but getting no attribute groupby error. My column don't have headers, so don't know if this is how to do it or is there another way?
f = open('data.txt' , 'r')
f_splits = [v for k, v in f.groupby()]
for f_split in f_splits:
print(f_split, sep = '\n')