I have also encountered this problem. I successfully ran my code in windows and received this message in ubuntu. This might be caused by a pandas issue, and the solution of Gemini 2.5pro corrected it. You can refer to it:
You have Pandas code that runs perfectly on one machine (e.g., Windows) but fails with an AttributeError: 'DataFrame' object has no attribute 'tolist' when moved to another (e.g., an Ubuntu server).
The error is often confusing because the traceback might point to a completely unrelated line of code (like a simple assignment df['col'] = 0), which is a known issue in older Pandas versions where the error is mis-reported.
The actual problematic line of code is almost certainly one where you call .tolist() directly after an .apply(axis=1):
Python
# This line fails on some systems
behavior_type = all_inter[...].apply(lambda x: [...], axis=1).tolist()
The Root Cause: Pandas Version Inconsistency
This issue is not caused by the operating system itself (Windows vs. Ubuntu), but by different versions of the Pandas library installed in the two environments.
On your Windows machine (Newer Pandas): apply(axis=1) returns a pandas.Series object. The Series object has a .tolist() method, so the code works.
On your Ubuntu machine (Older Pandas): When the lambda function returns a list, this older version of Pandas "expands" the results into a pandas.DataFrame object instead of a Series. The DataFrame object does not have a .tolist() method, which causes the AttributeError.
The Solution
To make your code robust and compatible with all Pandas versions, you must first access the underlying NumPy array using the .values attribute. Both Series and DataFrame objects support .values.
You only need to add .values before your .tolist() call.
Original Code:
Python
#
behavior_type = all_inter[columns].apply(lambda x: [...], axis=1).tolist()
Fixed Code:
Python
#
behavior_type = all_inter[columns].apply(lambda x: [...], axis=1).values.tolist()
This works because .values will return a NumPy array regardless of whether .apply() outputs a Series (on your Windows machine) or a DataFrame (on your Ubuntu machine), and NumPy arrays always have a .tolist() method.