pandas built-in str function, easy to split a multi-column data

Read data, name of the column can be - divided two symbol ''.

data = pd.read_csv('D:/test.csv', encoding='gbk')
data

Here Insert Picture Description
Series built-in functions performed str.split, obtain a listing of each of the divided cell.

data['name'].str.split('-')

Here Insert Picture Description

Add a parameter expand = True, the list separately, get two.

data['name'].str.split('-', expand=True)

Here Insert Picture Description

Published 27 original articles · won praise 14 · views 1909

Guess you like

Origin blog.csdn.net/A_pinkpig/article/details/105400286