我试图用csv中单个列中的空格替换所有逗号。我在这里尝试了以下方法:
function btnOnClick(btn) {
// first parentNode is td, second is tr
var row = btn.parentNode.parentNode;
// process row.
}
但是我收到以下错误:
<div class="row" style="margin-top:200px">
<div class="col-md-3">
<ul class="list-group">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-9">
<!--Put here your long paragraph-->
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br/><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
<br /><br /><br />
</div>
<div class="col-md-2 pull-right" style="position:fixed; right: 0">
<ul class="list-group ">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
<li class="list-group-item">First item</li>
</ul>
</div>
</div>
</div>
</div>
我对此错误消息的性质进行了一些研究,但我无法确定在分配之前我将引用变量的位置。
答案 0 :(得分:1)
假设df["column_name"]
的类型为string
,则应该有效:
df["column_name"].str.replace(","," ")
您可以将结果分配给列:
df["column_name"] = df["column_name"].str.replace(","," ")
答案 1 :(得分:0)
您可能必须将Regex标志设置为True
df["column_name"].replace(",", " ", regex=True)