擅长:python、mysql、java
<p>为了避免双重索引,请更改</p>
<pre><code>df['proxyCity'].ix[myindex ] = new_name
</code></pre>
<p>到</p>
^{pr2}$
<p>它更有效(更少的<code>__getitem__</code>函数调用),并且在大多数情况下,将消除<code>SettingWithCopyWarning</code>。在</p>
<p>但是请注意,如果<code>df</code>是另一个数据帧的子数据帧,则有可能发出<code>SettingWithCopyWarning</code>
即使使用<code>df.loc[...] = new_name</code>。在这里,Pandas警告说修改<code>df</code>不会影响其他数据帧。
如果这不是您的意图,那么可以安全地忽略<code>SettingWithCopyWarning</code>。有关使<code>SettingWithCopyWarning</code>静音的方法,请参见<a href="https://stackoverflow.com/q/40033471/190597">this post</a>。在</p>