简单的计算功能不起作用

时间:2016-08-16 17:01:25

标签: python pandas

我有以下代码,但我无法让它工作:

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 个答案:

答案 0 :(得分:1)

list

使用pd.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)