Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mengyuz/413831d7b2d27b4cd797 to your computer and use it in GitHub Desktop.
Save Mengyuz/413831d7b2d27b4cd797 to your computer and use it in GitHub Desktop.
import pandas
import pandasql
def filter_by_regular(filename):
'''
This function should read the csv file located at filename into a pandas dataframe,
and filter the dataframe to only rows where the 'DESCn' column has the value 'REGULAR'.
For example, if the pandas dataframe is as follows:
,C/A,UNIT,SCP,DATEn,TIMEn,DESCn,ENTRIESn,EXITSn
0,A002,R051,02-00-00,05-01-11,00:00:00,REGULAR,3144312,1088151
1,A002,R051,02-00-00,05-01-11,04:00:00,DOOR,3144335,1088159
2,A002,R051,02-00-00,05-01-11,08:00:00,REGULAR,3144353,1088177
3,A002,R051,02-00-00,05-01-11,12:00:00,DOOR,3144424,1088231
The dataframe will look like below after filtering to only rows where DESCn column
has the value 'REGULAR':
0,A002,R051,02-00-00,05-01-11,00:00:00,REGULAR,3144312,1088151
2,A002,R051,02-00-00,05-01-11,08:00:00,REGULAR,3144353,1088177
'''
turnstile_data = pandas.read_csv(filename)
return turnstile_data[turnstile_data['DESCn'] == 'REGULAR']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment