I have a DataFrame containing certain words with a unique identifier time
that is ascending.
For example:
words = ["a", "b", "a", "c", "d", "a", "b"]
df = pandas.DataFrame(words, columns=["word"])
df.index.name = "time"
word
time
0 a
1 b
2 a
3 c
4 d
5 a
6 b
I would like to count the number of unique values in the word
column over time
, to get a table like this:
word rolling_unique_word_count
time
0 a 1
1 b 2
2 a 2
3 c 3
4 d 4
5 a 4
6 b 4
Are there any build-in functions to perform this task?