我想将一个函数应用于 DataFrame 以使用 lambda 创建一个具有平均值的新数据帧,但出现此错误:
TypeError: ("Argument 'real' has wrong type (expected numpy.ndarray, got Series)", u'occurred at index 2018-01-02 00:00:00')
这是我的数据:
AA AAPL FB GOOG TSLA
Date
2018-01-02 55.169998 168.987320 181.419998 1065.000000 320.529999
2018-01-03 54.500000 168.957886 184.669998 1082.479980 317.250000
2018-01-04 54.700001 169.742706 184.330002 1086.400024 314.619995
2018-01-05 54.090000 171.675278 186.850006 1102.229980 316.579987
2018-01-08 55.000000 171.037628 188.279999 1106.939941 336.410004
2018-01-09 54.200001 171.018005 187.869995 1106.260010 333.690002
这就是我目前正在尝试的:
data = pd.read_csv('help.csv', parse_dates=True, index_col=0)
sma20 = data.apply(lambda x: ta.SMA(x, 20), axis=0)
print(sma20.tail())