擅长:python、mysql、java
<p>代码的问题在于这行代码:</p>
<p><code>filterdate = datetime.date(input())</code></p>
<p>在日期时间.日期()函数实际上无法正确解析日期,因此给您提供了此TypeError。在</p>
<h3>方法1</h3>
<p>你可以试试这个:</p>
<p><code>date = str(input())
year, month, day = map(int, date.split('-'))
filterdate = datetime.date(year, month, day)</code></p>
<p>然后你可以这样比较:</p>
<p><code>d1 = d1[(d1['New_Date'] > filterdate) & (d1['New_Date'] != 'NaT')]</code></p>
<h3>方法2</h3>
<p>解决此问题的另一种方法是使用datetime.date.fromisoformat()功能。在</p>
<p><code>filterdate = datetime.date.fromisoformat(input())</code></p>
<p>然后</p>
<p><code>d1 = d1[(d1['New_Date'] > filterdate) & (d1['New_Date'] != 'NaT')]</code></p>
<p>有关datetime的更多详细信息可以在这里找到:<a href="https://docs.python.org/3/library/datetime.html" rel="nofollow noreferrer">https://docs.python.org/3/library/datetime.html</a></p>