0
평균 시간, 평균 온도 및 습도를 특정 날짜와 시간으로 계산하는 프로그램을 작성하려고합니다.하지만 왜 '나노'값을 얻는 지 알 수 없습니다. .? 여기 내 코드는 어떤 아이디어입니까?Datetime 인덱싱을 사용하여 데이터 프레임 데이터 분석
import pandas as pd
import numpy as np
df = pd.DataFrame.from_csv('C:\Users\Joey\Desktop\Python\CSV\TM4CVC.csv',index_col = None)
df2 = pd.DataFrame({'temp':df['Ch1_Value'],
'press':df['Ch2_Value'],
'humid':df['Ch3_Value'], 'Date' : df['Date'], 'Time' : df['Time']})
df2['DateTime'] = pd.to_datetime(df2.apply(lambda x: x['Date']+ ' '+ x['Time'], 1))
df2.index = pd.to_datetime(df2.pop('DateTime'))
df3 = df2.drop(['Date', 'Time'], 1)
#------------------------------------------------------------------------------
def TempPressHumid(datetime_i, datetime_e):
index = df3[datetime_i:datetime_e]
out = {'temp_avg':np.mean(index['temp']),
'temp_std':np.std(index['temp']),
'press_avg':np.mean(index['press']),
'press_std':np.std(index['press']),
'humid_avg':np.mean(index['humid']),
'humid_std':np.std(index['humid'])}
print out
TempPressHumid(datetime_i = '2012-06-25 08:27:19', datetime_e = '2012-01-25 10:59:33')
내 출력은 다음과 같습니다
{'humid_std': nan, 'press_std': nan, 'humid_avg': nan, 'temp_avg': nan, 'temp_std': nan, 'press_avg': nan}
인쇄 DF3 저를 제공합니다
humid press temp
DateTime
2012-06-25 08:21:19 1004.0 21.2 26.0
2012-06-25 08:22:19 1004.0 21.2 26.0
2012-06-25 08:23:19 1004.1 21.3 26.0
-----------------------------------------
등 ...
데이터 샘플을 제공해 주실 수 있습니까? 'print df3'는 어떤 것을 출력하고 있습니까? 그렇다면 그것을 보여 주시겠습니까? –
인쇄 df3은 4 개 열로 데이터 프레임을 인쇄합니다 ... 시간, 습도, 온도, 누름 – Joey
읽을 수있는 형식을 유지하려면 원래 질문에 해당 데이터를 추가해야합니다. 또한 'pandas' 태그를 질문에 추가하면 노출이 늘어나고 답변을받을 확률이 높아집니다. –