首页 > 解决方案 > 文件打开困难

问题描述

我不想将 goog.npz 文件保存在下面建议的目录中,而是将其保存在这里:

file_path = 'C:/Users/.../goog.npz'

然后将 r (下面)替换为读取存储位置中的文件的内容。谢谢您的帮助!

# Load a numpy record array from yahoo csv data with fields date, open, close,
# volume, adj_close from the mpl-data/example directory. The record array
# stores the date as an np.datetime64 with a day unit ('D') in the date column.

with cbook.get_sample_data('goog.npz') as datafile:
    r = np.load(datafile)['price_data'].view(np.recarray)

标签: pythonnumpy

解决方案


只需在方法中指定文件的整个路径get_sample_data

with cbook.get_sample_data('C:Users/.../goog.npz') as datafile:
    r = np.load(datafile)['price_data'].view(np.recarray)

推荐阅读