I have a code that extracts tick data.
z=[SpanVariable1.text,datetime.now().strftime("%H:%M:%S")]
dfl=dfl.append(pd.DataFrame(z).T)
This part of the code is written in a loop that keeps running in real-time. So for the very first time when on completion of 1000 datapoints I execute the below commands
dfl.set_index(1, inplace = True)
print (dfl)
dfl.index = pd.to_datetime(dfl.index)
print (dfl)
which returns the data frame as intended.
0
1
08:04:04 441.95
08:04:04 441.95
08:04:04 441.95
08:04:04 441.95
08:04:04 441.95
... ...
08:04:29 441.95
08:04:29 441.95
08:04:29 441.95
08:04:29 441.95
08:04:29 441.95
[1001 rows x 1 columns]
0
1
2021-06-07 08:04:04 441.95
2021-06-07 08:04:04 441.95
2021-06-07 08:04:04 441.95
2021-06-07 08:04:04 441.95
2021-06-07 08:04:04 441.95
... ...
2021-06-07 08:04:29 441.95
2021-06-07 08:04:29 441.95
2021-06-07 08:04:29 441.95
2021-06-07 08:04:29 441.95
2021-06-07 08:04:29 441.95
[1001 rows x 1 columns]
But when loop forward for the next values that is 1002 all above index converts to NaN and Nat. except the last added row.
0
1
NaN 441.95
NaN 441.95
NaN 441.95
NaN 441.95
NaN 441.95
... ...
NaN 441.95
NaN 441.95
NaN 441.95
NaN 441.95
08:04:29 441.95
[1002 rows x 1 columns]
0
1
NaT 441.95
NaT 441.95
NaT 441.95
NaT 441.95
NaT 441.95
... ...
NaT 441.95
NaT 441.95
NaT 441.95
NaT 441.95
2021-06-07 08:04:29 441.95
[1002 rows x 1 columns]
I don't know what is the problem here. Is it possible that whenever I append live data to a data frame its index should be automatically kept as the current time?
Below code has reduced some steps but still I am not able to get rid of NaN and NaT after looping:
z=[SpanVariable1.text, datetime.now()]
dfl=dfl.append(pd.DataFrame(z).T)
dfl=dfl.append(pd.DataFrame(SpanVariable1.text).T)
dfl.set_index(1, inplace = True)
print (dfl)
again output for 1000 and 1001 loop comes respectively as below:
0
1
2021-06-07 09:46:44.571711 366.15
2021-06-07 09:46:44.600210 366.15
2021-06-07 09:46:44.628139 366.15
2021-06-07 09:46:44.654060 366.15
2021-06-07 09:46:44.679984 366.15
... ...
2021-06-07 09:47:13.492993 359.60
2021-06-07 09:47:13.528899 359.60
2021-06-07 09:47:13.556823 359.60
2021-06-07 09:47:13.583752 359.60
2021-06-07 09:47:13.611677 359.60
[1001 rows x 1 columns]
0
1
NaT 366.15
NaT 366.15
NaT 366.15
NaT 366.15
NaT 366.15
... ...
NaT 359.60
NaT 359.60
NaT 359.60
NaT 359.60
2021-06-07 09:47:13.643593 359.60
[1002 rows x 1 columns]
I think there is some problem in appending the new rows of live data into the existing dataframe. Please suggest some solution..