Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. data = pd.read_csv('/datasets/visits_eng.csv', sep='\t')
  4.  
  5. # filter excessively 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')
  11. good_data = good_data.query('60 <= time_spent <= 1000')
  12.  
  13. # consider data by individual gas station and by chains
  14. station_stat = data.pivot_table(index='id', values='time_spent', aggfunc='median')
  15. good_station_stat = good_data.pivot_table(index='id', values='time_spent', aggfunc='median')
  16. name_stat = data.pivot_table(index='name', values='time_spent')
  17. good_name_stat = good_data.pivot_table(index='name', values='time_spent', aggfunc='median')
  18. name_stat['good_time_spent'] = good_name_stat['time_spent']
  19.  
  20. id_name = good_data.pivot_table(index='id', values='name', aggfunc=['first', 'count'])
  21. id_name.columns = ['name', 'count']
  22. station_stat_full = id_name.join(good_station_stat)
  23. station_stat_multi = data.pivot_table(index='id', values=['time_spent', 'too_fast', 'too_slow'])
  24. print(station_stat_multi.corr())
  25. pd.plotting.scatter_matrix(station_stat_multi, figsize=(9, 9))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement