Skip to content

Instantly share code, notes, and snippets.

@Smarker
Last active August 21, 2018 19:55
Show Gist options
  • Save Smarker/65ceadaa673e78a9d9f15cef8819949c to your computer and use it in GitHub Desktop.
Save Smarker/65ceadaa673e78a9d9f15cef8819949c to your computer and use it in GitHub Desktop.
#user:smarker #pandas

Pandas

  1. Set date column as a DatetimeIndex
  2. Filter by df[start_date : end_date]

Example: Filter taxi data by a 24 hour time window

  1. Set date column tpep_pickup_datetime as DatetimeIndex
yellow_taxi_df['tpep_pickup_datetime'] = pd.to_datetime(yellow_taxi_df['tpep_pickup_datetime'])   
yellow_taxi_df.set_index('tpep_pickup_datetime',inplace=True)
  1. yellow_taxi_df['2017-12-01':'2017-12-01']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment