Re: Re: Untitled

From Scanty Tamarin, 11 Months ago, written in Plain Text, viewed 345 times. This paste is a reply to Re: Untitled from Corrupt Finch - view diff
URL http://codebin.org/view/6f3948b6 Embed
Download Paste or View Raw
  1. import pandas as pd
  2.  
  3. data = pd.read_csv('/datasets/visits.csv', sep='\t')
  4.  
  5. # фильтруем слишком быстрые и медленные заезды и АЗС
  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. # считаем данные по отдельным АЗС и по сетям
  14. station_stat = data.pivot_table(index='id', values='time_spent', aggfunc='median')
  15. good_stations_stat = good_data.pivot_table(index='id', values='time_spent', aggfunc='median')
  16.  
  17. stat = data.pivot_table(index='name', values='time_spent')
  18. good_stat = good_data.pivot_table(index='name', values='time_spent', aggfunc='median')
  19. stat['good_time_spent'] = good_stat['time_spent']
  20.  
  21. id_name = good_data.pivot_table(index='id', values='name', aggfunc=['first', 'count'])
  22. id_name.columns = ['name', 'count']
  23. station_stat_full = id_name.join(good_stations_stat)
  24.  
  25.  
  26. #ВОПРОС ТУТ! хочу переименовать колонки
  27. station_stat_full=station_stat_full[station_stat_full['count']>30]
  28. good_stat2 = station_stat_full.query('count > 30').pivot_table(index = 'id', values = 'time_spent', aggfunc = ['median', 'count'])
  29.  
  30. #ВОТ ТУТ
  31. good_stat2.columns['id','median_time', 'stations']
  32.  
  33. print(good_stat2.head())
  34.  

Replies to Re: Re: Untitled rss

Title Name Language When
Re: Re: Re: Untitled Blush Mosquito text 11 Months ago.

Reply to "Re: Re: Untitled"

Here you can reply to the paste above