通过pd.DataFrame(ticker:data.c)获取SyntaxError

时间:2018-09-08 04:39:45

标签: python pandas dataframe syntax-error

def load_tickers(ticker):
     fname = ( '%s.csv' % ticker.lower())
     data = pd.read_csv( fname, header = None, parse_dates = ['Date'],
                  names =['Date','Open','High','Low','c','Adj Close','Volume'])
     data = data.set_index('Date')
     x = pd.DataFrame(ticker: data.c)
     print(x)

load_tickers('AAPL')

我尝试运行代码,但由于某种原因,它引发了SyntaxError:

我该如何解决?

1 个答案:

答案 0 :(得分:0)

好像您想传递字典并忘记了花括号。试试这个:

x = pd.DataFrame({ticker: data.c})