【发布时间】:2020-04-05 01:25:05
【问题描述】:
我正在尝试将列表转换为 DataFrame。该列表来自一个文档,其中单词被单独分成单独的行。然后需要将该列表转换为 DataFrame。但是,在我运行我的 for 循环后,DataFrame 不包含任何信息。
import urllib.request
import pandas as pd
data = urllib.request.urlopen('https://www.w3.org/TR/PNG/iso_8859-1.txt')
wordlist = pd.DataFrame(columns = ['col1'])
for line in data:
for word in line.split():
print(word)
wordlist.append({'col1': word}, ignore_index=True)
单词拆分正确:
b'The'
b'following'
b'are'
b'the'
b'graphical'
b'(non-control)'
b'characters'
但是附加的数据框返回:
print(wordlist)
Empty DataFrame
Columns: [col1]
Index: []
【问题讨论】:
标签: python list dataframe append