Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to create a new column for values that are in the original column either using Excel or Python?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading