1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| file = r"D:\Stock_data\kdata\603956.csv" code = re.findall(r'\d{6}',file)[0] df = pd.read_csv(r"D:\Stock_data\kdata\603956.csv", index_col="date", parse_dates=["date"], usecols=[0,1,2,3,4,5,6] ) df["ma5"] = df["close"].rolling(5).mean() df["ma10"] = df["close"].rolling(10).mean() df["ma20"] = df["close"].rolling(20).mean() df = df[df.index >= '2022-06-01'] df.dropna(inplace=True) df['ma5'] = df['ma5'].map(lambda x :round(x,2)) df['ma10'] = df['ma10'].map(lambda x :round(x,2)) df['ma20'] = df['ma20'].map(lambda x :round(x,2)) df.head() date = list(map(lambda x: x.strftime("%Y-%m-%d"), df.index.tolist())) kl_data = df[["open", "close", "low","high"]].values.tolist() l_data = df[["ma5", "ma10", "ma20"]].values.tolist()
|