0

我有不同的数据框遵循这个例子:'AAPLdf,AMZNdf,GOOGLdf,......'等等

import matplotlib.pyplot as plt
from mpl_finance import candlestick_ohlc
import pandas as pd
import matplotlib.dates as mpl_dates
ticker = input("ticker:") + "df"
data = ticker
ohlc = data.loc[:, ['t', 'o', 'h', 'l', 'c']]

AttributeError:“str”对象没有属性“loc”

4

1 回答 1

1
ticker = input('ticker: ')

# this will return data as the dataframe from ticker, but it must be an exact match
data = eval(f'{ticker}df')  # -> equivalent to eval('GOOGLdf`), for example

# now you can use .loc 
data.loc[:, :]
于 2020-05-08T01:02:00.733 回答