擅长:python、mysql、java
<h3>在注释后编辑,索引是对象。</h3>
<p>索引是字符串对象。你需要把它们转换成数字。使用</p>
<pre><code>dr.index = pd.to_numeric(dr.index)
grp1.index = pd.to_numeric(grp1.index)
dr.sort_index()
grp1.sort_index()
</code></pre>
<p>那就试试剩下的</p>
<p>您可以过滤旧的stock“dr”数据帧以匹配售出的stock,然后减去,并分配回原始过滤的数据帧</p>
<pre><code># Filter the old stock dataframe so that you have matching index to the sold dataframe.
# Restrict just for menge_im_lager. Then subtract the sold stock
dr.loc[dr.index.isin(grp1.index), "menge_im_lager"] = (
dr.loc[dr.index.isin(grp1.index), "menge_im_lager"] - grp1["ArtMengen1"]
)
</code></pre>