def read_yahoo_data(fname):
pd.read_csv(fname, index_col=0, na_values="null").dropna()
toyota = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/TM.csv')
mitsui = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/MTU.csv')
mitsubishi = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/MITSY.csv')
apple = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/APPL.csv')
msft = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/MSFT.csv')
hpq = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/HPQ.csv')
nikkei = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/^N225.csv')
sp500 = read_yahoo_data('/Users/chenyuhan/Downloads/yahoo_finance/^GSPC.csv')
这是我使用的代码,文件的路径应该是true。 我正在使用MacOS。
答案 0 :(得分:0)
pandas csv_read从工作目录开始。所以你有两种方法可以做到这一点:
使用选项2,您的代码将是这样的:
def read_yahoo_data(fname):
import pandas as pd
import os
os.chdir('/Users/chenyuhan/Downloads/yahoo_finance/')
return pd.read_csv(fname, index_col=0, na_values="null").dropna()
你需要像这样传递文件名:
toyota = read_yahoo_data('TM.csv')
mitsui = read_yahoo_data('MTU.csv')
mitsubishi = read_yahoo_data('MITSY.csv')
apple = read_yahoo_data('APPL.csv')
msft = read_yahoo_data('MSFT.csv')
hpq = read_yahoo_data('HPQ.csv')
nikkei = read_yahoo_data('^N225.csv')
sp500 = read_yahoo_data('^GSPC.csv')