I am trying to produce some new columns based on data from different columns and rows. For instance, take the below series:
df = pd.Series(['Fruit[edit]','Apple','Orange','Banana','Vegetable[edit]','Celery','Beans','Kale'])
0 Fruit[edit]
1 Apple
2 Orange
3 Banana
4 Vegetable[edit]
5 Celery
6 Beans
7 Kale
I'm starting off with a series where the elements with "[edit]" represent the categories, and the rest are the names of the items that belong in that category. I would like to create two new columns, one showing the "Category" (i.e. fruit or vegetable) and another with the column title "Name" showing the items belonging to that category.
The end result should look something like this:
Category Name
0 Fruit Apple
1 Fruit Orange
2 Fruit Banana
3 Vegetable Celery
4 Vegetable Beans
5 Vegetable Kale
As we go down the series, I would like the code to recognize a new category (i.e. elements that endwith '[edit]' and store that as the updated category for the items until a newer category is reached.