Count Distinct Strings In Rolling Window Using Pandas + Python (with A Condition)
I want to calculate the number of distinct port numbers that exist between the current row and the 5 previous rows (sliding window) and this when the same address appears. For ins
Solution 1:
for index, row in df.iterrows():
small_df = df[index - 5:index]
df['uniques'][index] = len(small_df.unique())
Here's my quick shot at it.
Post a Comment for "Count Distinct Strings In Rolling Window Using Pandas + Python (with A Condition)"