Python Pandas - Split Column with multiple names in first name and last name column
i have a csv file with column like this:
and want to transfer it to this format:
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?
Solution 1:
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.