Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. def split(x, length):
  2.  
  3. splitted_string = x.split(',')
  4. result = [substr.strip() for substr in splitted_string if len(substr.strip())==length]
  5. result = ', '.join(result)
  6. return result
  7.  
  8.  
  9. df = pd.DataFrame({'a':["H33, H431, H450", "H21, H11, H521"]})
  10.  
  11. for length in [3, 4]:
  12. df[length] = df['a'].apply(lambda x: split(x, length))
  13.  
  14. >>> df.drop(['a'], axis=1)
  15. 3 4
  16. 0 H33 H431, H450
  17. 1 H21, H11 H521
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement