jeudi 14 novembre 2019

PYTHON: Filtering a dataset and truncating a date

I am fairly new to python, so any help would be greatly appreciated. I have a dataset that I need to filter down to specific events. For example, I have a column with dates and I need to know what dates are in the current month and have happened within the past week. The column is called POS_START_DATE with dates formatted like 2019-01-27T00:00:00-0500. I need to truncate that date and compare it to the previous week. No luck so far.

Here is my code so far:

## import data package
import datetime

## assign date variables
today = datetime.date.today()

six_day = datetime.timedelta(days = 6)

## Create week parameter
week = today - six_day

## Statement to extract recent job movements
if fields.POS_START_DATE < week and fields.POS_START_DATE > today:
      out1 += fields

Aucun commentaire:

Enregistrer un commentaire