- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试通过词汇来计算单词频率:
vocabulary = {}
for word in lemmatizer_results:
if word in vocabulary:
vocabulary[word] += 1
else:
vocabulary[word] = 1
在此之后,我尝试通过以下方式将结果转换为 DataFrame:
df = pd.DataFrame.from_dict(vocabulary, orient='index', columns=['word', 'frequency'])
如果字典的结构如下:
vocabulary = {'word1': [3],
'word2': [34]}
但我有这样的结构:
vocabulary = {'three': 1622,
'elephant': 66,
'power': 1070,
'story': 667,
'b': 65,
'paterson': 1,}
你能帮我根据这些数据创建 DF 吗?谢谢!
最佳答案
你们很接近。使用orient='index'
,字典键转换为数据帧索引,而值转换为数据。因此您可以重命名索引,然后重置它。
df = pd.DataFrame.from_dict(vocabulary, orient='index', columns=['frequency'])\
.rename_axis('word').reset_index()
print(df)
word frequency
0 three 1622
1 elephant 66
2 power 1070
3 story 667
4 b 65
5 paterson 1
关于python - 如何使用非标准分隔符从词汇创建 DF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54409680/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
我们如何知道使用哪个词汇/命名空间来描述带有 RDFa 的数据? 我看过很多使用 xmlns:dcterms="http://purl.org/dc/terms/" 的例子或 xmlns:sioc="
我正在尝试理解 BERT 词汇 here .它有 1000 个 [unusedxxx] token 。我不遵循这些 token 的用法。我了解其他特殊 token ,如 [SEP]、[CLS],但 [
我需要一些词汇方面的帮助,我不经常使用 Oracle,但我熟悉 MySQL 和 SQL Server。 我有一个应用程序需要升级和迁移,执行此操作的部分过程涉及导出到 XML 文件,允许安装程序创建新
我主要使用 Ruby 来执行此操作,但到目前为止我的攻击计划如下: 使用 gems rdf、rdf-rdfa 和 rdf-microdata 或 mida 来解析给定任何 URI 的数据。我认为最好映
我是一名优秀的程序员,十分优秀!