same code diffrent result with Jupyter notebook and Python Script

The same Python code produces different output results. I want to implement a cumulative calculation for continuous grouping.

The calculation result in Jupyter notebook is normal, but it is incorrect in the Python Script node. It seems to be caused by missing values when shifting down by one row. Is there any reason for this? Any tips are greatly appreciated.

(python 3.11, KNIME 5.2 )

import pandas as pd
data = {'Category': ['A', 'A', 'A', 'B', 'B', 'C', 'C', 'A', 'A'],
'Value': [1, 2, 3, 5, 1, 2, 1, 8, 2]}
df = pd.DataFrame(data)
df['Cumulative Sum'] = df.groupby((df['Category'] != df['Category'].shift(1)).cumsum())['Value'].cumsum()
print(df)