2016-08-16 103 views
1

我有下面的代码,但我无法得到它的工作:简单的计算功能

import matplotlib.pyplot as plt 
import numpy as np 
import pandas as pd 

def test_calc(date, price, performance): 
    test = pd.DataFrame(columns=('date'), index=('date')) 
    test['date'] = date 
    test['new_value'] = price * (1 + performance) 
    return(test) 

print(test_calc(1, 100, 0.05)) 

这个问题似乎是: TypeError: Index(...) must be called with a collection of some kind, 'date' was passed

我并不需要它是一个DataFrame顺便一提。我之所以选择它是因为我之前使用过它。其他一切都失败了,例如test = []

回答

1

使用listpd.DataFrame(columns=[], index=[])

def test_calc(date, price, performance): 
    test = pd.DataFrame(columns=['date'], index=['date']) 
    test['date'] = date 
    test['new_value'] = price * (1 + performance) 
    return(test) 
+0

完美,谢谢! – Spurious