擅长:python、mysql、java
<p>我使用的解决方法是创建一个方法<a href="https://stackoverflow.com/questions/34156830/leave-dates-as-strings-using-read-excel-function-from-pandas-in-python">undate</a>(从现有解决方案中使用),将日期还原为原始格式。并在所有DataFrame列中运行该方法。实现是蛮力的,但它是有效的:P。我的最终代码是这样的。你知道吗</p>
<pre><code>def undate(x):
if pd.isnull(x):
return x
try:
return x.strftime('%d/%m/%Y')
except AttributeError:
return x
except Exception:
raise
for col in df.columns:
df[col] = df[col].apply(undate)
</code></pre>