df
ts_code close ma50 ma200 ma50_to_close ma200_to_close
0 000902.SZ 12.20 11.9982 9.5290 1.016819 1.280302
4 000902.SZ 11.94 12.0378 9.4423 0.991876 1.264522
0 000799.SZ 100.39 88.6272 55.8328 1.132722 1.798047
4 000799.SZ 101.33 85.9644 54.5181 1.178744 1.858649
Expected dataframe
column names:
ts_code curr_close curr_ma50 curr_ma200 curr_ma50_to_close curr_ma200_to_close l5d_close l5d_ma50 l5d_ma200 l5d_ma50_to_close l5d_ma200_to_close
data
0 000902.SZ 12.20 11.9982 9.5290 1.016819 1.280302 11.94 12.0378 9.4423 0.991876 1.264522
1 000799.SZ 100.39 88.6272 55.8328 1.132722 1.798047 101.33 85.9644 54.5181 1.178744 1.858649
Because it's hard to show expected dataframe. I show column names and data separately.
Try and refer
I refer this post. It's similar but the data structure is not the same.