<jupyter_start><jupyter_text><NAME><jupyter_code>import csv
import reverse_geocoder as gc
from pandas import read_csv
from geopy.distance import great_circle
from datetime import datetime
from scipy.stats import ttest_ind as ttest

d = read_csv('taxi-trips.xls')
pickup_points = [i['name'] for i in
                 gc.search(
                     d.apply(lambda x:
                                  (x.pickup_latitude, 
                                   x.pickup_longitude), axis=1).tolist())]
dropoff_points = [i['name'] for i in gc.search(
    d.apply(lambda x: (
        x.dropoff_latitude, 
        x.dropoff_longitude), axis=1).tolist())]
d['pickup_district'] = pickup_points
d['dropoff_district'] = dropoff_points
from collections import Counter
counts = Counter(d['pickup_district'])
counts.most_common()[:5]
d['pickup_district'].value_counts().head(5).plot.bar()
counts = Counter(d['dropoff_district'])
counts.most_common()[:5]
d['dropoff_district'].value_counts().head(5).plot.bar()
a = []
for i,j,k,l in zip(
    d.pickup_latitude,
    d.pickup_longitude, 
    d.dropoff_latitude,
    d.dropoff_longitude):
    
    a += [great_circle((i,j),(k,l)).kilometers]

d['distance'] = a
def dt(dtime):
    return datetime.strptime(dtime,'%Y-%m-%d %H:%M:%S')

def tod(dtime):
    if 7 <= dt(dtime).hour < 9:
        return "Rush-Hour-Morning"
    elif 9 <= dt(dtime).hour < 16:
        return "Afternoon"
    elif 16 <= dt(dtime).hour < 18:
        return "Rush-Hour-Evening"
    elif dt(dtime).hour < 23:
        return "Evening"
    else:
        return "Late-Night"
a = []
for x in d.pickup_datetime:
    a+=[tod(x)]
d['time-of-the-day'] = a
a = []
for x,y in zip(
    d.dropoff_datetime,
    d.pickup_datetime):
    dif = dt(x)-dt(y)
    a+=[dif.total_seconds()]
d['duration'] = a
for t in set(d['time-of-the-day']):
    print(t,'\t',d[d['time-of-the-day']==t].distance.mean())
d[['time-of-the-day','distance']].groupby('time-of-the-day').mean().plot.bar()
for t in set(d['time-of-the-day']):
    print(t,'\t',d[d['time-of-the-day']==t].duration.mean(),'seconds')
d[['time-of-the-day','duration']].groupby('time-of-the-day').mean().plot.bar()<jupyter_output>Afternoon 	 963.9227460253572 seconds
Late-Night 	 912.2391106251139 seconds
Evening 	 880.0437396311115 seconds
Rush-Hour-Morning 	 918.4887158766138 seconds
Rush-Hour-Evening 	 1024.4945520581114 seconds<jupyter_text>HYPOTHESIS TESTING-- Distance is longer for larger groups<jupyter_code>onepassenger = d.passenger_count<=1;

print (d[onepassenger].duration.mean(), d[~onepassenger].duration.mean())
test = ttest(d[onepassenger].distance, d[~onepassenger].distance)

if test[1] >= 0.05:
    print ('Null Cannot Be Rejected')
else:
    print ('Reject Null Hypothesis!')<jupyter_output>898.4021780392901 998.784384313494
Reject Null Hypothesis!<jupyter_text>Distance is longer on weekdays<jupyter_code>week_end =[] ;
week_day =[] ;

for i in d.pickup_datetime:
    week_end+=[dt(i).weekday()>4]
    week_day+=[not dt(i).weekday()>4]

print (d[week_end].duration.mean(), d[week_day].duration.mean())
test = ttest(d[week_end].distance, d[week_day].distance)

if test[1] >= 0.05:
    print ('Null Cannot Be Rejected')
else:
    print ('Reject Null Hypothesis!')<jupyter_output>893.4216166388201 941.2284026787746
Reject Null Hypothesis!
{'fraction_non_alphanumeric': 0.16585809581564584, 'fraction_numerical': 0.05215281989084294, 'mean_word_length': 3.9460269865067468, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '165333', 'license': 'Apache-2.0', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1264, 'n_words': 224, 'path': 'CS210-Step1.ipynb', 'repo_name': 'egehansezer/CS210', 'size': '3304'}