I'm working on dataframes with PANDAS in Python. I read a csv file with pandas.read_csv(...)
. In this csv file the column 'possible_stops'
contains lists (each cells in this column looks like : [ ]
or [str0,str1]
).
I want to iterate over the rows with itertuples()
and for each row i want to access the list inside 'possible_stops'
column.
However, the dtype of this column is object
and when i look for the type of a specific cell (type(row.possible_stops)
) it returns str
. I think there is something to do with dtype = ..
inside the read_csv
method but i don't exactly know what to do.
How can i convert cells inside this column into lists ?
Thanks very much!
EDIT : the resulting df looks like :
latitude longitude gps_speed possible_stops
1.05869 1574942547 0.0 [['Bapeaume', 2]]
1.05862 1573910439 0.0 [['Bapeaume', 2]]
1.05862 1573910441 0.0 [['Bapeaume', 2]]
1.05862 1573910443 0.0 [['Bapeaume', 2]]
1.05862 1573910445 0.0 [['Bapeaume', 2]]
1.05862 1573910447 0.0 [['Bapeaume', 2]]