I want to do this with python
and pandas
.
Let's suppose that I have the following:
file_id text
1 I am the first document. I am a nice document.
2 I am the second document. I am an even nicer document.
and I finally want to have the following:
file_id text
1 I am the first document
1 I am a nice document
2 I am the second document
2 I am an even nicer document
So I want the text of each file to be splitted at every fullstop and to create new lines for each of the tokens of these texts.
What is the most efficient way to do this?
Use:
Explanation:
First use
DataFrame.pop
for extract column, remove last.
bySeries.str.rstrip
and split by withSeries.str.split
with escape.
because special regex character, reshape byDataFrame.stack
for Series,DataFrame.reset_index
andrename
for Series forDataFrame.join
to original.