Python (Pandas): count of records between values at a given time (Packets in Flight) -
i have dataframe based on packet logs wireless channel has indexes "transmitted"
, "received"
beingness respective floats of time since start.
i want distribution of how many packets in air @ time. @ moment
t_packets = pd.series([df[(df.transmitted < t) & (t < df.received)].count().max() t in range(tmax)])
this computationally nasty (~40s each iteration) haven't been able work out improve way limited pandas experience.
anyone got ideas 'better' way accomplish this?
basically, think want flatten info , create timeseries out of it.
tx = pd.dataframe(index=df.transmitted) rx = pd.dataframe(index=df.received) tx['p'] = 1 #adding packet rx['p'] = -1 #receiving packet #create time series here t = pd.concat([tx, rx]) t.sort().cumsum()
it's easy here figuring out actual times. can resample create clearer, should it.
edit: adding how resample seconds:
#assuming indexed times in seconds t.sort(inplace=true) t.index = pd.to_datetime(t.index * 10e9) #to convert nanoseconds seconds t.resample('s', how='sum').cumsum()
python pandas dataframes
No comments:
Post a Comment