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

Data Cleaning How to split Pandas column

It has been sometime since i tried working in python

I have this data frame with many columns too many to name

  last/first    location    job    department
  smith john    Vancouver   A1     servers
  rogers steve  Toronto     A2     eng
  Rogers Dave   Toronto     A4     HR

how to I remove caps in the last/first column and also split the last/first column by " "?

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

goal

  last      first    location    job    department
  smith     john     Vancouver   A1     servers
  rogers    steve    Toronto     A2     eng
  rogers    dave     Toronto     A4     HR
  

>Solution :

IIUC, you could use str.lower and str.split:

df[['last', 'first']] = (df.pop('last/first')
                           .str.lower()
                           .str.split(n=1, expand=True)
                         )

output:

    location job department    last  first
0  Vancouver  A1    servers   smith   john
1    Toronto  A2        eng  rogers  steve
2    Toronto  A4         HR  rogers   dave
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