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

Extract text from a series into new columns

I’ve tries the following code with the following error message:

AttributeError: ‘DataFrame’ object has no attribute ‘str’

I’m referencing a string series, then why am i getting a "Dataframe" error?

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

df['PO'] =  df['extract'].str.extract(r"(?:^(?=[A-Z\d/-]+$)|\bPO\W*)([A-Z\d/-]+)")

>Solution :

Problem is with duplicated columns names, so if select one column extract get all columns in DataFrame.

print (df['extract'])

For deduplicted is simpliest set columns names or some another solution:

df.columns= ['a','b']
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