Issue
I got a series like this
0 stand and on the top of the m
1 be aware of the p
2 in the night o
3 tt
4 锉
Here is my code
x1=x.str.split(pat='/').str[0].copy()
x2=x1.str.split(expand=True).copy()
x2['combined']=x2[x2.columns].apply(lambda row: '+'.join(row.values.astype(str)), axis=1)
x2['combined']
the result of x2 is
0 stand+and+on+the+top+of+the+m
1 be+aware+of+the+p+None+None+None
2 in+the+night+o+None+None+None+None
3 tt+None+None+None+None+None+None+None
4 Nan+Nan+Nan+Nan+Nan+Nan+Nan+Nan
The outcome I want is
0 stand+and+on+the+top+of+the+m
1 be+aware+of+the+p
2 in+the+night+o
3 tt
4
what should I do?
Solution
Just replace the spacer:
x.str.replace('\s+', '+', regex=True)
output:
0 stand+and+on+the+top+of+the+m
1 be+aware+of+the+p
2 in+the+night+o
3 tt
4 锉
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.