New answers tagged

2

You probably want to replace def main(): with if __name__ == "__main__": This second form means only run the indented code if this module specifically is called, not if it is imported. I'm assuming after the provided code, you just call main(), which is fine, but if you have no intentions of using main outside of this module, you should use the ...


6

Setup I have considered first column as DatetimeIndex looking at the provided data where dates does not have a column name. d="""date,ts_code,close,low 2021-03-10,APPL,6.67,6.66 2021-03-10,AMA,20.24,20.12 2021-03-11,APPL,6.75,6.50 2021-03-11,AMA,21.10,20.40 2021-03-12,AMA,21.31,21.03 2021-03-12,APPL,6.81,6.76 2021-03-15,AMA,21.43,20.95 2021-03-...


0

As I worked more with these data, I realized that two problems were keeping me away from a decent performance: There is a big overhead with using pandas, and The data about visits is sparse, and I should make use of it So, the same data can be calculated by starting with an np.zeros matrix of a corresponding size, and setting 1s within the range of each ...


3

I think it is slow because your periods_breakdown is gigantic, and to fill each cell you have to compute its value. But what you compute is whether each individual visit overlapped with each other visit, which is overkill. If what you want is to know when there is two visits (or more) overlapping, but don't need to know which specific ones, you can simply ...


0

Inspired by Gulzar at Stackoverflow. I do not realize it works until after a night's sleep. So, below is enough: offset_orig = range(m) offset_train, offset_test = train_test_split(offset_orig, train_size=0.7, random_state=666) x_train = x.iloc[offset_train] # later x_test = x.iloc[offset_test] The offset_train list ([0, 2, ...]) has the same feature in ...


1

You need to drop your use of geopy. So far as I can see it does not support vectorised inverse geodesics. Instead use cartopy which inherently supports this. The following example code uses random instead of real data, but with the same size as your real data, and completes in about one second. distances and close are both matrices whose rows correspond to ...


Top 50 recent answers are included