Skip to content

Conversation

@ueshin
Copy link
Collaborator

@ueshin ueshin commented Apr 18, 2020

Adding expand parameter support if n is a positive integer in Series.str.split/rsplit with a couple of restrictions that:

  • n parameter must be a positive integer
  • the number of columns will always be n + 1.

E.g.,

>>> kser = ks.Series(['A_1', 'A_2', 'A_3', 'A_4', 'A_5'])
>>> kser
0    A_1
1    A_2
2    A_3
3    A_4
4    A_5
Name: 0, dtype: object
>>> kser.str.split('_', n=1, expand=True)
   0  1
0  A  1
1  A  2
2  A  3
3  A  4
4  A  5
>>> kser.str.split('_', n=2, expand=True)
   0  1     2
0  A  1  None
1  A  2  None
2  A  3  None
3  A  4  None
4  A  5  None

The last example is different from pandas'.

>>> kser.to_pandas().str.split('_', n=2, expand=True)
   0  1
0  A  1
1  A  2
2  A  3
3  A  4
4  A  5

Resolves #1421.

@ueshin ueshin requested a review from HyukjinKwon April 18, 2020 01:58
@ueshin ueshin mentioned this pull request Apr 18, 2020
@HyukjinKwon HyukjinKwon merged commit 93932bf into databricks:master Apr 20, 2020
@ueshin ueshin deleted the split_expand branch April 20, 2020 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

str.split(expand = True)

2 participants