0

I am working with data files of a single column containing strings, but sometimes the content of one rows carries over to the next one, like so:

...
"This is a str-
        -ing"
...

This happens multiple times in each file in a non predictable way: is there a method in Python, preferably using pandas, to attach the content of the second row to the first, eliminating the - separator? I have looked far and wide in SO and elsewhere for similar questions, but no solution seems to really apply to my case. Thanks in advance for any suggestions.

1

1 Answer 1

1

Assuming that the pattern here is consistently [hyphen] [newline] [whitespace] [hyphen], you could write a regex that matches that pattern and replace all occurrences of the pattern with an empty string before processing the file in pandas. The regex would look something like "-\w*\n\w*-". The "re" library in python can be used to perform the replace operation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.