字符串没有属性 .loc

A string doesn't have the attribute .loc

我有不同的数据帧遵循示例:'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'

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[:, :]