Python: Convert dataframe into a list with string items inside list
It worked for me without .values()
:
list = df[col_name].astype(str).tolist()
You can just cast the column dtype using astype(str)
and then convert to list using .values.tolist()
, this returns a numpy array using .values
which has a member function to convert this to a list:
In [321]:
us_zips['zipcode'].astype(str).values.tolist()
Out[321]:
['10601', '60047', '50301', '10606']