fork download
  1. import pandas as pd
  2.  
  3. strings = [
  4. "THIS IS an example",
  5. "ALSO this",
  6. "ONE LAST",
  7. "J. one more"
  8. ]
  9. df1 = pd.DataFrame(strings, columns=["header"])
  10. df1 = df1.join(
  11. df1['header'].str.extract(
  12. '^(?P<header1>[A-Z]+(?:[^\S\n]+[A-Z]+)*)?(?:(?:^|[^\S\n]+)(?P<header2>.+))?$',
  13. expand=True
  14. )
  15. .fillna('')
  16. )
  17.  
  18. print(df1)
  19.  
Success #stdin #stdout 0.52s 60408KB
stdin
Standard input is empty
stdout
               header   header1      header2
0  THIS IS an example   THIS IS   an example
1           ALSO this      ALSO         this
2            ONE LAST  ONE LAST             
3         J. one more            J. one more