Created
June 5, 2015 15:11
-
-
Save Mengyuz/413831d7b2d27b4cd797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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