Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.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 在df列中每N个字符后插入换行符 < P> >我想插入一个断线(>Br.P>),因为您没有共享任何数据,我将只考虑 DF作为您的数据框,它具有尽可能多的文本列。现在,对于每一行,您可以简单地使用应用< /Cuff>函数。< /P> changedData = df["Messages"].apply(lambda row:insertNewlines(row), axis=1)_Python - Fatal编程技术网

Python 在df列中每N个字符后插入换行符 < P> >我想插入一个断线(>Br.P>),因为您没有共享任何数据,我将只考虑 DF作为您的数据框,它具有尽可能多的文本列。现在,对于每一行,您可以简单地使用应用< /Cuff>函数。< /P> changedData = df["Messages"].apply(lambda row:insertNewlines(row), axis=1)

Python 在df列中每N个字符后插入换行符 < P> >我想插入一个断线(>Br.P>),因为您没有共享任何数据,我将只考虑 DF作为您的数据框,它具有尽可能多的文本列。现在,对于每一行,您可以简单地使用应用< /Cuff>函数。< /P> changedData = df["Messages"].apply(lambda row:insertNewlines(row), axis=1),python,Python,现在,在您的insertNewlines()方法中,您可以做任何您想做的事情,您可以编辑整行内容 def insertNewlines(text, lineLength=int(n)): if len(text) <= lineLength: return text elif text[lineLength] != ' ': return insertNewlines(text[:], lineLength + 1) else:

现在,在您的
insertNewlines()
方法中,您可以做任何您想做的事情,您可以编辑整行内容

def insertNewlines(text, lineLength=int(n)):
    if len(text) <= lineLength:
       return text
    elif text[lineLength] != ' ':
       return insertNewlines(text[:], lineLength + 1)
    else:
       return text[:lineLength] + '<br>' + insertNewlines(text[lineLength + 1:], lineLength)
def insertNewlines(text,lineLength=int(n)):

如果len(text)您尝试过df[foo]中的行
:row=insertNewLines(第5行)
?尝试:
fmt--split only--width=72 so.txt
不幸的是pstatix这种方法不起作用。你能澄清一下你的评论吗@故意留空,我从未使用过fmt,所以这段代码对我来说很陌生。感谢你的尝试,但不幸的是,这产生了一个错误。我已经更新了上面的答案,所以我的问题应该是b现在它更可读。如果您需要更改的列只是
df[“Messages”]
,那么,编辑的代码应该按照您的预期工作。如果没有,请分享您的错误。现在就可以了,谢谢您的帮助。祝您有一个愉快的一天。很好,就是说,早些时候我还以为您希望循环浏览所有列。谢谢
Excerpts:
Can this issue be closed?
The other precedences are OK; as far as I can tell... not worth messing around in the code for no demonstrable benefit.
we ran into this issue on our platform. it's possibly very specific to our setup; but the patch should cause no problems for any other setup as well. simplifying this into on line is of course possible. i can't really tell you any more about it; since this issue was fixed in our local implementation about one year ago by some colleague. in preparation for our migration to the current version of shindig and opensocial 0.9 i'm revising all patches and feature additions we did over the last year and will be looking at which are worth comitting. so you can expect some more small issues in the next weeks ;)
Completely non-related and probably belongs in another jira _x0089_ÛÒ but I've added a small patch to fix two comment typos in HttpTransact (I know authorized can be spelt with an s _x0089_ÛÒ but we don't do that anywhere else in the code)
Already fixed in UIMA-1379.
changedData = df["Messages"].apply(lambda row:insertNewlines(row), axis=1) 
def insertNewlines(text, lineLength=int(n)):
    if len(text) <= lineLength:
       return text
    elif text[lineLength] != ' ':
       return insertNewlines(text[:], lineLength + 1)
    else:
       return text[:lineLength] + '<br>' + insertNewlines(text[lineLength + 1:], lineLength)