shift

pandas shift time series with missing values

筅森魡賤 提交于 2021-02-08 02:10:41
问题 I have a times series with some missing entries, that looks like this: date value --------------- 2000 5 2001 10 2003 8 2004 72 2005 12 2007 13 I would like to do create a column for the "previous_value". But I only want it to show values for consecutive years. So I want it to look like this: date value previous_value ------------------------------- 2000 5 nan 2001 10 5 2003 8 nan 2004 72 8 2005 12 72 2007 13 nan However just applying pandas shift function directly to the column 'value' would

matplotlib: How to pick up shift click on figure?

岁酱吖の 提交于 2021-02-07 06:57:16
问题 I have a matplotlib and I have created a button_press_event like this: self.fig.canvas.mpl_connect('button_press_event', self.onClick) def onClick(self, event) if event.button == 1: # draw some artists on left click elif event.button == 2: # draw a vertical line on the mouse x location on wheel click elif event.button == 3: # clear artists on right click Now is it possible to modify the wheel click handler to something like this elif event.button == 2 or (event.button == 1 and event.key ==

How do I shift columns (left or right) in a matrix?

家住魔仙堡 提交于 2021-01-28 22:41:58
问题 I would like to non-circularly shift my matrix and then have zeros padded to either the left or right (depending on the shift) i.e. if the matrix shifts to the right, zeros would be padded to the left. I am using MATLAB 2019b and my code so far looks like this: %dummy data data = rand(5, 16); channelSink = 9; %this variable will either be >layerIV, <layerIV or =layerIV layerIV = 7; diff = layerIV - channelSink; for channel = 1:16 if channelSink > layerIV %shift columns to the left by ab(diff)

Shift rows in pandas dataframe in a specific order

落花浮王杯 提交于 2021-01-27 18:02:13
问题 I have a pandas dataframe which looks like this: df = pd.DataFrame({ 'job': ['football','football', 'football', 'basketball', 'basketball', 'basketball', 'hokey', 'hokey', 'hokey', 'football','football', 'football', 'basketball', 'basketball', 'basketball', 'hokey', 'hokey', 'hokey'], 'team': [4.0,5.0,9.0,2.0,3.0,6.0,1.0,7.0,8.0, 4.0,5.0,9.0,2.0,3.0,6.0,1.0,7.0,8.0], 'cluster': [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1] }) Each cluster contains 9 teams. Each cluster has 3 teams of each type of

Reshift Nan values column dataframe if match with list

送分小仙女□ 提交于 2020-12-07 15:50:13
问题 I want to rearrange column name values that contains Nan. Condition that i want is, if string in list match with column[1], it will only reshift column values that contain row under matched string, so its my dataframe before shifted. [in] : df [Out]: column1 column2 column3 0 aba abab 800.0 900.0 1 aaa acc 900.0 60.0 2 bba jka 809.0 400.0 3 fff yy 521.0 490.0 4 hkm asa j 290.0 321.0 5 daa rr oo 88.0 Nan 6 jtuy ww ddw Nan 600.0 8 bkam ftf Nan Nan 9 fgqefc Nan Nan 10 daas we fg Nan Nan 11 judv

data.table | faster row-wise recursive update within group

你。 提交于 2020-07-04 05:42:43
问题 I have to do the following recursive row-by-row operation to obtain z : myfun = function (xb, a, b) { z = NULL for (t in 1:length(xb)) { if (t >= 2) { a[t] = b[t-1] + xb[t] } z[t] = rnorm(1, mean = a[t]) b[t] = a[t] + z[t] } return(z) } set.seed(1) n_smpl = 1e6 ni = 5 id = rep(1:n_smpl, each = ni) smpl = data.table(id) smpl[, time := 1:.N, by = id] a_init = 1; b_init = 1 smpl[, ':=' (a = a_init, b = b_init)] smpl[, xb := (1:.N)*id, by = id] smpl[, z := myfun(xb, a, b), by = id] I would like