I have a pandas Data frame which represent a list of sentences when every row is a word and it got an ID corresponding to its location in the sentence.
It looks something like:
ID FORM
0 1 A
1 2 word
2 3 in
3 4 the
4 5 first
5 6 sentence
6 7 .
7 1 The
8 2 second
9 3 sentence
10 4 .
11 1 the
12 2 third
13 3 sentence
...
How can I add an extra column named "Sentence" which will correspond to which sentence the given word is belong and my Data frame would look like that:
ID FORM Sentence
0 1 A 1
1 2 word 1
2 3 in 1
3 4 the 1
4 5 first 1
5 6 sentence 1
6 7 . 1
7 1 The 2
8 2 second 2
9 3 sentence 2
10 4 . 2
11 1 the 3
12 2 third 3
13 3 sentence 3
I can make it done by iterating the data frame and create a series manually, but it looks ugly and not very pytonic. Is there a nice way to use pandas to do it for me?