擅长:python、mysql、java
<p>您只需避免复制索引问题,而不复制它:</p>
<pre class="lang-py prettyprint-override"><code>df = pd.DataFrame()
for r in range(5):
df = df.append({'type':'teine', 'id':r}, ignore_index=True)
# Problem line
df = pd.concat([df.reset_index(drop=True), pd.DataFrame({'type':'teine', 'id':5}, index=[max(df.index.values)+1])], sort=True)
dfCopy = df.copy()
df.query("(type == 'teine')", inplace=True)
df = dfCopy[~dfCopy.isin(df).all(axis=1)]
</code></pre>
<p>或者,您可以在连接后重置索引:</p>
<pre class="lang-py prettyprint-override"><code>df = pd.DataFrame()
for r in range(5):
df = df.append({'type':'teine', 'id':r}, ignore_index=True)
# Problem line
df = pd.concat([df, pd.DataFrame({'type':'teine', 'id':5}, index=[0])], sort=True).reset_index(drop=True)
dfCopy = df.copy()
df.query("(type == 'teine')", inplace=True)
df = dfCopy[~dfCopy.isin(df).all(axis=1)]
</code></pre>