I figured out how to solve the issue. The problem can be resolved by downgrading the pandas version to 1.2.5 or lower. Any version higher than 1.2.5 seems to cause the failure. However, I am not sure why this is happening.
If anyone has insights into why versions higher than 1.2.5 of pandas might be causing this issue, I would appreciate any explanations or suggestions.
Here is how you can downgrade pandas:
pip uninstall pandas
pip install pandas==1.2.5
After downgrading, the code should work as expected on both Windows and Linux.