bust a list of string from a dataframe column like shown with my code:

d = {'text': ["Hello", "How are you","From","Liban"]}
df = pd.DataFrame(data=d)
df

My list will have

    List_text = ["Hello","How are you","From","Liban"].

Thank you

2 Answers

1
Erfan On

Use Series.tolist:

list_text = df.text.tolist()

print(list_text)

['Hello', 'How are you', 'From', 'Liban']
0
Rebin On

you can iterate over elements in the target column and add the elements you want to an empty list.

d = {'text': ["Hello", "How are you","From","Liban"]}
df = pd.DataFrame(d)
rows,columns=df.shape

list_text=[] #your empty list 
for index in range(rows): #iteration over the dataframe
    list_text.append(df.iat[index,0])

print(list_text)