1
  #Filter the data by displaying data with date >2018:
import datetime as dt

df2[df2['Year'] > dt.date(year > 2018)]

 the year column has a dtype of datetime64[ns]

I have checked the documentation and still cant find a way to filter the date to only display rows with year > 2018

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
  • 2
    Please don't post images of code, data, or Tracebacks. [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – wwii May 18 '22 at 17:35
  • 2
    If the datatype of 'Year' is just an integer, you could directly do `df2[df2['Year']] > 2018` – S P Sharan May 18 '22 at 17:37
  • the data type of year is datetime64[ns] i have already tried the above and since its not an integer i have had no luck – feras200015 May 18 '22 at 17:40
  • Just curious how you create a datetime64 like year? – Ynjxsjmh May 18 '22 at 18:00
  • `df = = df[df['date'].dt.strftime('%Y') > '2018']` – NoobVB May 18 '22 at 18:04
  • i tried this with both single equal sign and double and it returns all false – feras200015 May 18 '22 at 18:21
  • Please provide entire or at least part of your dataframe. Mention me with @Drakax when you've updated your question or I won't receive notification ;) – Drakax Jun 01 '22 at 00:16

0 Answers0