【问题标题】:How to split strings from a CSV column into a list?如何将字符串从 CSV 列拆分为列表?
【发布时间】:2018-05-22 17:25:44
【问题描述】:

我想从一个名为“文本”的 CSV 列的单词中列出一个列表,该列由字符串组成

这就是我所拥有的:

def html_words():

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

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

这是我得到的错误:

> 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'

【问题讨论】:

    标签: string python-3.x pandas dataframe


    【解决方案1】:

    您可能需要做的是:

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

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

    【讨论】:

      猜你喜欢
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 2018-10-24
      • 1970-01-01
      相关资源
      最近更新 更多