string list into list pandas 1

string list into list pandas

import ast 

# initializing string representation of a list 
ini_list = "[1, 2, 3, 4, 5]"
  
# Converting string to list 
res = ast.literal_eval(ini_list) 
  
# printing final result and its type 
print ("final list", res) 
print (type(res)) 

Here is what the above code is Doing:
1. We have a string representation of a list.
2. We use the ast.literal_eval() function to convert the string to a list.
3. We print the final result and its type.

Similar Posts