Python Forum
Vectorized parsing in dataFrame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vectorized parsing in dataFrame
#2
You can use .str.extract() with regular expression pattern. Examples:
Output:
In [13]: df = pd.DataFrame({'C':['123456', '789012', '345678'], 'D':['12345678', '123', '2']}) In [14]: df Out[14]:         C         D 0  123456  12345678 1  789012       123 2  345678         2 In [15]: df.C.str.extract("(.{3})(.{3})")  # works only for strings with length 6 Out[15]:      0    1 0  123  456 1  789  012 2  345  678 In [16]: df.D.str.extract("(?=(.{,3})).*?(.{,3}$)")  # should work for any length of s, same as s[:3] and s[-3:] Out[16]:      0    1 0  123  678 1  123  123 2    2    2
Reply


Messages In This Thread
Vectorized parsing in dataFrame - by aibrain - Apr-02-2017, 10:49 AM
RE: Vectorized parsing in dataFrame - by zivoni - Apr-02-2017, 12:03 PM
RE: Vectorized parsing in dataFrame - by aibrain - Apr-07-2017, 11:43 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020