Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expand parameter if n is a positive integer in Series.str.split/rsplit. #1432

Merged
merged 1 commit into from
Apr 20, 2020

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