1

I have the following data-frame:

row_num        causes                     accident_type
0              slip and fall              physical injury
1              gas leak; smoking          fire accident
2              distracted driving         car accident

My goal is to process the above data-frame such that any row with an entry in the causes column that has a ";" is split into the number of causes in that entry (while having the content of that original row duplicated into the split rows). So in this case, row_num 1 will be split into two rows. This is the expected output:

row_num        causes                     accident_type
0              slip and fall              physical injury
1              gas leak                   fire accident
1              smoking                    fire accident
2              distracted driving         car accident

Is there a pandas function that can quickly do this splitting and copying, and also deletes the original row so that there is no row with semicolon in it?

Sam
  • 641
  • 1
  • 7
  • 17

0 Answers0