I have the below Pandas Series with values that look like this:
| Info |
|---|
| # ID 3.22.33.2 |
| Location: Texas |
| Address: 1321 madeupstreet |
| Name: mike b |
| Address: 6.3.1 |
There are almost 1000 rows with this data so the problem I am having is:
Question
Can I run a code in python or Excel to extract the values from these rows in such a way that it would place ID#s on a separate column, Location in a another column …etc
So it would look something like this:
| IDs | Location | Address | Name |
|---|---|---|---|
| 3.22.33.2 | Texas | 1321 Madeupstreet | mike b |
Some items wont have a Name and in that case, could it just leave it blank? or write No name found?
I tried creating separate lists (this data came from a text file) but that method is not working for me, and I do not have any code to share at the moment.so I copy pasted all the values into an excel sheet.
Note (I do not care about the second Address line, so if it is easier to ignore that is fine).
>Solution :
Based on the specific series and for the sake of easiness I suggest you can try:
df['Index'] = df['Info'].replace("# ","",regex=True).str.split().str[0]
df['Values'] = [' '.join(x) for x in df['Info'].replace("# ","",regex=True).str.split().str[1:]]
output = df.set_index('Index').drop(columns='Info').T
Returning:
Index ID Location: Address: Name: Address:
Values 3.22.33.2 Texas 1321 madeupstreet mike b 6.3.1