Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中读取大字符串并拆分每个单词花费了太多时间_Python_Python 3.x_String - Fatal编程技术网

在python中读取大字符串并拆分每个单词花费了太多时间

在python中读取大字符串并拆分每个单词花费了太多时间,python,python-3.x,string,Python,Python 3.x,String,我正在读一个有评论的dataframe专栏。使用下面的代码读取数据需要很长时间。有没有办法让这更快 for val in df.Description: val = str(val) tokens = val.split() for i in range(len(tokens)): tokens[i] = tokens[i].lower() for words in tokens: comment = com

我正在读一个有评论的dataframe专栏。使用下面的代码读取数据需要很长时间。有没有办法让这更快

for val in df.Description:
    val = str(val)
    tokens = val.split()  
    for i in range(len(tokens)):
        tokens[i] = tokens[i].lower()  
        for words in tokens:
            comment = comment + words + ''

df.Description是一列注释(基本上是电子邮件文本)

更新:假设df.Description是您的列,这可能会有帮助:

arr_string = df.Description.astype(str).values.tolist()
for val in arr_string:
    for words in val:
            comment = ''.join([comment, words])

查看。

更新:假设df.Description是您的列,这可能会有帮助:

arr_string = df.Description.astype(str).values.tolist()
for val in arr_string:
    for words in val:
            comment = ''.join([comment, words])

看一看。

你能说得更清楚一些吗,比如举一些例子来说明
df.Description
中的
val
是什么样子,以及
comment
是什么。
comment=comment+words+'
是构建字符串的一种非常低效的方法。建立一个字符串列表,然后
'.join()
把它放在末尾。你能说得更清楚一些吗,例如,给出一些例子来说明
df.Description
中的
val
是什么样子的,以及
注释是什么。
comment=comment+words+'
是一种非常低效的建立字符串的方法。建立一个字符串列表,然后
'.join()
在endAttributeError:“Series”对象没有属性“split”AttributeError:“Series”对象没有属性“split”