Python Pandas - Split Column with multiple names in first name and last name column

axelhaar

i have a csv file with column like this:

enter image description here

and want to transfer it to this format:

enter image description here

unfortunately, so far I could not find a good way to do this. Is it possible with Python and Pandas to split the columns like this?

heavelock

You don't even need pandas for that. Here is a code. Not tested as you did not provide data.

For the future, it would be awesome if you provided any code you tried to write as well as data that would make helping you easier.

names = []
with open("filename.csv", 'r') as f:
    for line in f.readlines():
        split_names = line.split(' ')
        names.append(split_names[0], ' '.join(split_names[1:]))

PS: The code assumes there is no header in the file. So you will have to either remove the header or skip the line in the code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Pandas split name column into first and last name if contains one space

Pandas split column name

Pandas Full Name Split into First , Middle and Last Names

How to get first name and last name when last name is multiple names in pandas

SUBSTRING To split column name get first and last base on the space

How to split a "full name" column into a separate first and last name column in Google Big Query?

VERTICA Database :- how to get distinct count of "first names" where first name and last name are stored in single column?

Split Pandas column name by delimiter

split array of first and last names into variables of first and last name in JavaScript

split pandas column prepending with actual column name

How do I change a column in Excel with Last Name, First Name into a column with First Name Last Name (no comma)

What's the most efficient way of truncating the names in a first_name and last_name column to 1 character?

Split column names and create new column from data in column name

pandas: split a string column into multiple columns and dynamically name columns

python - Create a column combining the first and last name columns with IF Statement

python dataframe pandas drop multiple column using column name

If last names are similar in [Name] column, fill in missing values of another column

Pandas Passing Variable Names into Column Name

What is the quickest way to create new column of all unique last names for a given first name in Base R

Splitting first and last names and then recombining first initial with last name if there are multiple people with the same last name

Retrieve column name of last month of transactions in Pandas

How to replace one column name with multiple column names in existing pandas dataframe?

How to change column names based on the first three characters of the column name

Combine first and last name and update into full name column for each row

Referring to column names by name

Move last column title name and put to be on first column on all rows

How to split first name and last name in two columns when there are 2 last names

Convert first row of pandas dataframe to column name

Handle pandas column names in concat with dynamic column name