0

I'm trying to split the content below into multiple columns, separated by | or multiple pipes. For example, what you see below should have split into 8 columns.

By the end of the week, you will have the opportunity to: | | Explain the accrual basis of accounting and the reasons for adjusting entries. | Prepare adjusting entries for deferrals. | Prepare adjusting entries for accruals. | Prepare an adjusted trial balance and closing entries. | | |

I used the following code:

df2 = df1['los'].str.split('|', expand=True) 

I noticed that some rows didn't get split into different columns using the code above. Any ideas why?

Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73
  • It will be 9 columns not 8. Also what are those rows that didn't split into 9 columns? – NYC Coder Oct 29 '20 at 21:02
  • Sorry, yes 9 columns. I used final.head() to check the outcome and that was where I saw that .split() didn't work for some rows. https://github.com/hellokatechan/clean_los/blob/main/clean_los_manual%20.ipynb – iamkatechan Oct 29 '20 at 21:43

1 Answers1

0

You can use regular expression pattern:

df['col'].str.split('( ?\| ?)+') 
Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73