0

I have a CSV file that has a name and email column. My goal is to map a new column, which is to separate the column names into two columns, first names and last names. The following sample table.

Names, Email aa bb, [email protected] bb cc, [email protected] cc dd, [email protected] 

To be

First Name, Last Name, Email aa, bb, [email protected] bb, cc, [email protected] cc, dd, [email protected] 

honestly, I am currently only able to read files with Pandas, I have read a number of articles about mapping in Pandas, but I have not found the right one.

Thank you.

2
  • 2
    Did you check str.split with expand equals true? Commented Feb 19, 2019 at 3:14
  • 1
    Also check out my answer to that question. Commented Feb 19, 2019 at 4:32

1 Answer 1

2

You could try:

df[['First_Name','Last_Name']]=df.pop('Names').str.split(" ",expand=True) print(df) Email First_Name Last_Name 0 [email protected] aa bb 1 [email protected] bb cc 2 [email protected] cc dd 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.