Похоже, вы пытаетесь двумя способами вставить слова в слова информационного блока в единый список?
import pandas as pd
data = [{"NOTES1": "annual report",
"NOTES2": "all of these",
"NOTES3": "we urge and"},
{"NOTES1": "business 10-k",
"NOTES2": "state are",
"NOTES3": "we urge you to"},
{"NOTES1": "business annual ",
"NOTES2": "all of these",
"NOTES3": "we various"}]
df = pd.DataFrame(data)
# should probably call this word_list
df_word_list = []
# I'm assuming your data looks like above
df_notes = df[["NOTES1" , "NOTES2", "NOTES3"]]
откуда вы сводитесь?
# one_list = list(flatten(df_notes.values.tolist()))
1) Я думаю, что вы пытаетесь сгладить список? Можно сделать это, используя понимание списка:
flat_list1 = [item for sublist in df_notes.values.tolist() for item in sublist]
print(flat_list1)
# ['annual report', 'all of these', 'we urge and', 'business 10-k', 'state are', 'we urge you to', 'business annual ', 'all of these', 'we various']
Или используя два цикла for:
flat_list2 = []
for sublist in df_notes.values.tolist():
print(sublist)
for item in sublist:
print(item)
flat_list2.append(item)
print(flat_list2)
# ['annual report', 'all of these', 'we urge and', 'business 10-k', 'state are', 'we urge you to', 'business annual ', 'all of these', 'we various']
2) Я думаю, что вы пытаетесь перебрать каждую строку? Другой способ сделать это, используя itterows:
word_list = []
for row_num, row_series in df_notes.iterrows():
print("Row Number:\t", row_num)
row_list = row_series.tolist()
print("Row Data:\t",row_list)
word_list = row_list + word_list
print(word_list)
# ['annual report', 'all of these', 'we urge and', 'business 10-k', 'state are', 'we urge you to', 'business annual ', 'all of these', 'we various']