python - align timeseries in pandas -
i have 2 time series.
df=pd.dataframe([ ['1/10/12',10], ['1/11/12',11], ['1/12/12',13], ['1/14/12',12], ], columns=['time','n']) df.index=pd.to_datetime(df['time']) df1=pd.dataframe([ ['1/13/12',88], ],columns=['time','n'] ) df1.index=pd.to_datetime(df1['time'])
i trying align time series index in order. guessing reindex_like need not sure how use it.
here desired output
time n 0 1/10/12 10 1 1/11/12 11 2 1/12/12 13 3 1/13/12 88 4 1/14/12 12
here need:
df.append(df1).sort().reset_index(drop=true)
if need compile more pieces together, more efficient use pd.concat(<names of dataframes list>)
.
p.s. code bit redundant: don't need cast time
index if don't need there. can sort values based on column, this:
import pandas pd df=pd.dataframe([ ['1/10/12',10], ['1/11/12',11], ['1/12/12',13], ['1/14/12',12], ], columns=['time','n']) df1=pd.dataframe([ ['1/13/12',88], ],columns=['time','n'] ) df.append(df1).sort_values('time')
Comments
Post a Comment