首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将CSV列中的字符串拆分到列表中?

如何将CSV列中的字符串拆分到列表中?
EN

Stack Overflow用户
提问于 2018-05-23 01:25:44
回答 1查看 136关注 0票数 0

我想用名为'text‘的CSV列的单词创建一个列表,该列由字符串组成

这就是我所拥有的:

代码语言:javascript
复制
def html_words():

    legits_text = pd.read_csv('/Users/pmpilla/Documents/phishing/html_text.csv', delimiter=',')

    list_text = legits_text["text"].split(" ")

这是我得到的错误:

代码语言:javascript
复制
> Traceback (most recent call last):
  File "/Users/pmpilla/Documents/phishing/html_words/legit_path_words.py", line 70, in <module>
    html_words()
  File "/Users/pmpilla/Documents/phishing/html_words/legit_path_words.py", line 30, in html_words
    list_text = legits_text["text"].split(" ")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/generic.py", line 3614, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'split'
EN

回答 1

Stack Overflow用户

发布于 2018-05-23 01:32:19

您可能需要做的是:

代码语言:javascript
复制
list_text = legits_text["text"].str.split(" ")

您可能还需要使用参数expand=True来创建新列,而不是列表。参考:https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50473385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档