有没有这将是一个组合的等同的任何功能df.isin()和df[col].str.contains()? 例如,假设我有系列 s = pd.Series(['cat','hat','dog','fog','pet']),并且我想找到s包含的任何一个的所有地方['og', 'at'],那么我想得到除“宠物”以外的所有东西。 我有一个解决方案,但这很不雅致: searchfor = ['og', 'at'] found = [s.str.contains(x) for x in searchfor] result = pd.DataFrame[found] result.any() 有一个更好的方法吗?
这个简单的代码仅尝试用冒号替换分号(在i指定的位置)不起作用: for i in range(0,len(line)): if (line[i]==";" and i in rightindexarray): line[i]=":" 它给出了错误 line[i]=":" TypeError: 'str' object does not support item assignment 如何解决此问题,以冒号代替分号?使用replace不起作用,因为该函数不使用索引-可能有一些我不想替换的分号。 例 在字符串中,我可能有许多分号,例如“ Hei der!; Hello there;!;” 我知道我想替换哪些(我在字符串中有索引)。使用替换无法正常工作,因为我无法对其使用索引。
我正在尝试打开.html文件作为一个大的长字符串。这是我得到的: open(FILE, 'index.html') or die "Can't read file 'filename' [$!]\n"; $document = <FILE>; close (FILE); print $document; 结果是: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN 但是,我希望结果看起来像: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 这样,我可以更轻松地搜索整个文档。