2016-08-16 100 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