我有以下代码,但我无法让它工作:
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 = []
。
答案 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)