shift - Pandas shifting uneven timeseries data -


I have some randomly stamped time series data, with timestamps and comments on every timestamp, irregular form in pandes This means that the timestamps are uneven, for example, there is no difference between two timestamps.

For example, data may be taken

  timestamp property 0 100 1 200 4 300 6 400 6 401 7 500 14 506 24 550 ..... 59 700 61 750 64 800   

Here's a timestamp that says some time has passed since the time of origin. As you can see, we can get data in the same timestamp, 6 seconds in this case. In fact, timestamps are strictly different, just can not measure that second resolution change.

Now I need to move the rain data forward, say that I want to change the whole data in 60 seconds or one minute. Then the target output is

  the timestamp property 0 750 1 800   

then the 0 digit matches 61 points and the score 1 matches matches 64 points.

Now I can do this by writing something filthy, but as much as possible I am looking to use the facilities of Inbuilt Ponds. If I had been regularly or evenly stacked, I could only use the change () function. But the fact is that the series is uneven, it makes it a bit difficult. Any idea of ​​Panda experts will be welcomed. I think this will be a common problem facing so much thanks!

Edit: Added a second, more elegant way to do this. I do not know what will happen if you had a timestamp of 61 on the timestamp 1 and twice. I think it will choose the first 61 timestamps, but not sure. new_stamps = pd.Series (DF ['timestamp']. Max () + 1)) moved = pd.DataFrame (new_stamps) shifted.column = ['timestamp'] merged = Pd.merge (df, moved, on = 'timestamp', how) = 'external') merged ['timestamp'] = merged ['timestamp'] - 60 merged = merged source (column = 'timestamp) '). Bfill () result = pd.merge (df, merge, on = 'timestamp')


[original post] I do not think in an inbuilt or elegant way to do this can. If this is more elegant than your "something filthy", then I think about how:

  lookup_dict = {} def assignor (line): lookup_dict [row [ 'Timestamp']] = line ['attribute'] df.apply (assignor, axis = 1) sorted_keys = sorted (lookup_dict.keys) df ['property_shifted'] = no defs (line, shift_amt) : I'm in the sorted_keys: if i & gt; = Line ['timestamp'] + shift_amt: line ['property_shined'] = lookup_dict [i] return line df = df.apply (get_shifted_property, shift_amt = 60, axis = 1)    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -