2017-12-21 5 views
0

내 마지막 4 개 기록을 새 행을 추가는 다음과 같습니다내 데이터 세트의 기존 dataframe/시리즈

date Outbound 

11/26/2017 21:00 175.5846438 
11/26/2017 22:00 181.1182961 
11/26/2017 23:00 112.011672 
11/27/2017 00:00 43.99501014 

내가 샘플 예측의 내 아웃 짓을하고 다음 예측 한 7 개 출력 11월 27일 01 즉, : 00, 02:00 등 .. 내 예보는 다음과 같은 목록 형식입니다 : [100, 120, 130 ....]

예측을 날짜와 함께 my 데이터 프레임 또는 시리즈, 데이터를 플롯해야합니다.

답변

0

새 DataFrame을 만들 수 있습니다. 추가 목록을 만든 다음 기존 목록과 병합하십시오. 가장 쉬운 방법은 데이터를 날짜 목록으로 구성된 사전 목록으로 사용할 수있는 경우입니다. 나는. 물론

import datetime 
import pandas 

# Calculating your predictions (this should be replaced with an 
# appropriate algorithm that matches your case) 

latest_entry = df_original.iloc[-1] 
latest_datetime = latest_entry['date'] 

# We assume lastest_datetime is a Python datetime object. 
# The loop below will create 10 predictions. This should be adjusted to make 
# sense for your program. I'm assuming the function `compute_prediction()` 
# will generate the predicted value. Again, this you probably want to tweak 
# to make it work in your program :) 
# The computed predictions will be stored inside a list of dicts. 

predictions = list() 

for _ in range(10): 
    predicted_date = latest_datetime + datetime.timedelta(hours=1) 
    predicted_value = compute_prediction() 

    tmp_dict = { 
     'date': predicted_date, 'Outbound': predicted_value 
    } 
    predictions.append(tmp_dict) 

# Convert the list of dictionaries into a data frame. 
df_predictions = pandas.DataFrame.from_dict(predictions) 

# Append the values of your new data frame to the original one. 
df_concatenated = pandas.concat(df_original, df_predictions) 

, predictions 요구에 사용 된 date 키가 원래 데이터 프레임에 사용 된 것과 같은 유형이 될 : 같은 것을 (나는 df_original 있으리라 믿고있어이 원래 값으로 데이터 프레임) . 그 결과로 df_concatenated 두 데이터 프레임을 함께 갖게됩니다. 결과를 플롯하려면 df_concatenated.plot()으로 전화를 걸거나 필요한 적절한 플롯 기능을 호출하면됩니다.

복수 데이터 프레임 병합에 대한 자세한 내용은 here을 참조하십시오.

+0

입력 해 주셔서 감사합니다. 그러나 마지막 날짜 값을 알 수없는 경우, 예 : 지난 날짜 값은 11/27/2017 00:00입니다.이를보고 사전을 준비했습니다. , 하드 코딩 된 값을 갖고 싶지 않습니다. 마지막 값이 예를 들어 다른 것이 었으면 어떻게 될까요 : 11/27/2017 10:00, 내 지점이 있으리라 믿습니다. 마지막 값을 가져 오는 방법 1 시간 씩 증가합니다 ... –

+0

안녕하세요, 저는 답변을 수정하여 최신 항목을 가져 와서 1 시간 간격으로 예측을 생성합니다. 물론 위의 코드는 컨텍스트에서 작동하도록 약간의 조정이 필요합니다 (예 : 예측을 계산하는 방식). –

+0

이 답변이 도움이 되었다면 동의하십시오. https://stackoverflow.com/help/someone-answers –

관련 문제