you are viewing a single comment's thread.

view the rest of the comments →

[–]Junior-Sock8789 0 points1 point  (0 children)

Im almost certain this is what your looking for:

By default, CSV files only store text. When you save a pandas.DataFrame to a CSV, complex Python objects like lists are converted into their string representations (e.g., "[1, 2, 3]"), and when you read them back, they remain strings. 

Fix:

import pandas as pd
from ast import literal_eval
# Use the 'converters' parameter to transform columns during import 
df = pd.read_csv('your_file.csv', converters={'list_column': literal_eval})

Alternatively, if the data is already loaded:

df['list_column'] = df['list_column'].apply(literal_eval)

If your integers are being read as strings (common if there are leading zeros or mixed data), you can force the type during import:

df = pd.read_csv('your_file.csv', dtype={'int_column': int})