Im trying to create an empty DataFrame
for which I will then constantly be appending rows to using the time stamp when the data arrives as index.
This is to code I have so far:
import pandas as pd
import datetime
df = pd.DataFrame(columns=['a','b'],index=pd.DatetimeIndex(freq='s'))
df.loc[event.get_datetime()] = event.get_data()
The problem Im having is with freq
in the DateTimeIndex
, the data is not arriving at any predefined intervalls, it is ju when some event tiggers. And also in the code above I need to specify a start and enddate for the index I dont want that I just want to be able to append rows whenever they arrive.
Set up empty with pd.to_datetime
df = pd.DataFrame(columns=['a','b'], index=pd.to_datetime([]))
Then do this
df.loc[pd.Timestamp('now')] = pd.Series([1, 2], ['a', 'b'])
df
a b
2018-06-10 20:52:52.025426 1 2
The first argument of DateTimeIndex
is data
. Try setting data
to an empty list. If you want to define the start time, end time, or frequency, take a look at the other arguments for DateTimeIndex
.
df = pd.DataFrame(columns=['a','b'], index=pd.DatetimeIndex([], name='startime'))
If you're trying to index on time delta values, also consider
df = pd.DataFrame(columns=['a','b'], index=pd.TimedeltaIndex([]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With