Advertisement
korenizla

df_temp

Feb 22nd, 2023
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. df_arc = df_arc[df_arc['Реактивная мощность'] >= 0] # избавимся от аномалий в df_arc
  2. # и в df_temp
  3. df_temp = df_temp[df_temp['Температура'] >= 1500]
  4.  
  5. # преобразовываем в нужный формат
  6. df_temp['Время замера'] = pd.to_datetime(df_temp['Время замера'], format='%Y-%m-%d %H:%M:%S')
  7.  
  8. # сводная таблица с последней температурой
  9. df_temp_last = pd.pivot_table(df_temp, index='key', values=['Время замера', 'Температура'],
  10.                               aggfunc={'Время замера' : 'max', 'Температура' : 'last'})
  11. df_temp_last = df_temp_last.reset_index()
  12. df_temp_last.set_axis(['key','time_last','temp_last'], axis = 'columns', inplace = True)
  13.  
  14. # сводная таблица с первой температурой
  15. df_temp_first = pd.pivot_table(df_temp, index='key', values=['Время замера', 'Температура'],
  16.                                aggfunc={'Время замера' : 'min', 'Температура' : 'first'})
  17. df_temp_first = df_temp_first.reset_index()
  18. df_temp_first.set_axis(['key', 'time_first','temp_first'], axis = 'columns', inplace = True)
  19.  
  20. # объединяем таблицы
  21. df = df_temp_first.merge(df_temp_last, on='key', how='left')\
  22.                   .reindex(columns=['key', 'time_first', 'temp_first', 'time_last', 'temp_last'])
  23.  
  24. df.info()
  25.  
  26. <class 'pandas.core.frame.DataFrame'>
  27. Int64Index: 3215 entries, 0 to 3214
  28. Data columns (total 5 columns):
  29.  #   Column      Non-Null Count  Dtype        
  30. ---  ------      --------------  -----        
  31.  0   key         3215 non-null   int64        
  32.  1   time_first  3215 non-null   datetime64[ns]
  33.  2   temp_first  3215 non-null   float64      
  34.  3   time_last   3215 non-null   datetime64[ns]
  35.  4   temp_last   3215 non-null   float64      
  36. dtypes: datetime64[ns](2), float64(2), int64(1)
  37. memory usage: 150.7 KB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement