pandas 加载股票日线数据 load_csv

 1 def load_csv():
 2     # 从csv文件读取股票日线数据
 3     file = "data/300474.csv"
 4     df = pd.read_csv(file, encoding="gbk")
 5     # 数据以日期升序排序
 6     df.sort_values(by="日期", ascending=True, inplace=True)
 7     # 重置index为升序的值
 8     df.reset_index(drop=True, inplace=True)
 9     # 以条件获取数据
10     index = df.index[pd.to_datetime(df["日期"]) <= pd.to_datetime('2016-09-10')]
11     quote = df.loc[index]
12     print(index, "\n", quote)

 

posted @ 2022-09-21 17:11  dilex  阅读(94)  评论(0编辑  收藏  举报