Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. data = pd.read_csv('/datasets/visits_eng.csv', sep='\t')
  4.  
  5. # filter abnormally fast and slow visits and gas stations
  6. data['too_fast'] = data['time_spent'] < 60
  7. data['too_slow'] = data['time_spent'] > 1000
  8. too_fast_stat = data.pivot_table(index='id', values='too_fast')
  9. good_ids = too_fast_stat.query('too_fast < 0.5')
  10. good_data = data.query('id in @good_ids.index and 60 <= time_spent <= 1000')
  11.  
  12. # consider data by individual gas station and by chains
  13. station_stat = data.pivot_table(index='id', values='time_spent', aggfunc='median')
  14. good_stations_stat = good_data.pivot_table(index='id', values='time_spent', aggfunc='median')
  15. good_stations_stat.hist(bins=50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement