I have a text file that includes time series data, but there are some gaps in the time series and values. ( i only insert the first 5 rows of data as example the time series is from 1996 to 2010)
o_data is a (dataframe):
Time Value
01.01.1996 00:00 nan
01.01.1996 00:10 10.4
01.01.1996 00:20 10.4
01.01.1996 00:50 10.4
I create a time series with Freq 10 min:
idx = pd.date_range(start=min(o_data.Time), end=max(o_data.Time), freq='10Min')
out[ ]: idx --> (DatetimeIndex)
0
01.01.1996 00:00
01.01.1996 00:10
01.01.1996 00:20
01.01.1996 00:30
01.01.1996 00:40
01.01.1996 00:50
and I want to assign the values from (o_data)Dataframe to time index which has been created already and fill value gaps by NaN:
new_o_data = (pd.DataFrame( o_data, index=idx ).fillna('NaN'))
the desired result is: (the result that I want to have)
Time Value
01.01.1996 00:00 NaN
01.01.1996 00:10 10.4
01.01.1996 00:20 10.4
01.01.1996 00:30 NaN
01.01.1996 00:40 NaN
01.01.1996 00:50 10.4
but what I received after running the code are empty columns of Time and Value:
out[ ]: new_o_data --> (DataFrame)
index Time Value
1996-01-01 00:00:00 NaN NaN
1996-01-01 00:10:00 NaN NaN
1996-01-01 00:20:00 NaN NaN
1996-01-01 00:30:00 NaN NaN
1996-01-01 00:40:00 NaN NaN
1996-01-01 00:50:00 NaN NaN
I would appreciate it if you could help me.