Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def split(x, length):
- splitted_string = x.split(',')
- result = [substr.strip() for substr in splitted_string if len(substr.strip())==length]
- result = ', '.join(result)
- return result
- df = pd.DataFrame({'a':["H33, H431, H450", "H21, H11, H521"]})
- for length in [3, 4]:
- df[length] = df['a'].apply(lambda x: split(x, length))
- >>> df.drop(['a'], axis=1)
- 3 4
- 0 H33 H431, H450
- 1 H21, H11 H521
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement