與此代碼開始:創建索引數據幀
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
vento=pd.read_csv('dados_tpm.txt')
vento.rename(columns={'Dia_Mes_Ano_Hora_Minuto': 'Data'})
vento.set_index('Data')
數據幀是這樣的:
Data Vel Dir
2016-07-12 16:26:00 2.4 21.0
2016-07-12 16:27:00 1.7 17.8
2016-07-12 16:29:00 14.3 14.9
該指數已在日期時間。目的是替代指數上方通過下面這段代碼創建了一個新的指數,並保持所有的值在文託列:
vento3 = pd.DataFrame({'Data':pd.date_range(start='2016-07-12 16:17:00',end='2017-04-30 22:34:00',freq='1Min')})
vento3.set_index('Data')
得到這個指標,如:
Data
2016-07-12 16:26:00
2016-07-12 16:27:00
2016-07-12 16:28:00
2016-07-12 16:29:00
所需的輸出:
Data Vel Dir
2016-07-12 16:26:00 2.4 21.0
2016-07-12 16:27:00 1.7 17.8
2016-07-12 16:28:00 NaN NaN
2016-07-12 16:29:00 14.3 14.9
如果有人可以幫忙,會很感激。
你應該能夠只是做'vento.reindex(pd.date_range(開始='2016年7月12日16:17: 00',end ='2017-04-30 22:34:00',freq ='1Min'))' – EdChum
如果我使用這個,我得到這個錯誤:ValueError:不能從重複軸重新索引 –
我得到相同的錯誤。我不知道這是爲什麼。 – Moondra