Convert Python list to pandas Series

Hypothetical Ninja picture Hypothetical Ninja · Feb 8, 2014 · Viewed 79.7k times · Source

What is the method to convert a Python list of strings to a pd.Series object?

(pandas Series objects can be converted to list using tolist() method--but how to do the reverse conversion?)

Answer

Colin Bernet picture Colin Bernet · Feb 8, 2014

I understand that your list is in fact a list of lists

import pandas as pd

thelist = [ ['sentence 1'], ['sentence 2'], ['sentence 3'] ]
df = pd.Series( (v[0] for v in thelist) )