Вам необходимо:
txt = " remember all those walls we built remember those times"
words = txt.split()
for word in words:
print(word + " " + str(txt.count(word)))
import pandas as pd
mytable = pd.DataFrame()
for word in words:
tempdf = pd.DataFrame ({"word" : [word], "frequency" : [txt.count(word)]})
mytable = mytable.append(tempdf)
print(mytable)
или лучше с pd.concat
:
import pandas as pd
txt = " remember all those walls we built remember those times"
words = txt.split()
for word in words:
print(word + " " + str(txt.count(word)) )
my_table=pd.concat([pd.DataFrame ({"word" : [word], "frequency" : [txt.count(word)]}) for word in words])
print(mytable)
имейте в виду, чтоВы также можете update
словарь и затем создать кадр данных в конце