I have a text file which I'm reading with pandas and nltk which is just the alphabet with three colums and an & in the last position for a total of 27 characters. I want to be able to parse the rows into a list. How could I go about doing that?
Asked
Active
Viewed 51 times
-1
-
Can you provide examples of the data, what code have you tried, and what's your expected result? See https://stackoverflow.com/q/20109391/6692898 – RichieV Aug 02 '20 at 23:34
1 Answers
0
I'm assuming you have a dataframe and you just want to change each row to a list. This can be done with the following:
# Create an empty list
rowlist =[]
# Iterate over each row
for index, rows in df.iterrows():
# Create list for the current row
my_list =[rows.col1, rows.col2, rows.col3]
# append the list to the final list
rowlist.append(my_list)
# Print the list
print(rowlist)

ldren
- 159
- 5