我拼命地尝试使用 Pyxll 来编写一些获取一堆数组的 excel 函数,在 Python 中加载它们,将它们转换为 pandas DataFrames,稍微处理一下数据,然后返回最终的 DataFrame。现在,为了返回 DataFrame,我找到了pyxll 示例,但无论我如何尝试,我似乎都无法将加载的 excel 数组转换为我可以使用的 pandas DataFrames。
例如,我尝试使用下面的代码,但没有运气。也许如果我有某种方式知道 Python 中加载了什么以及它的外观,也许我有更好的机会了解如何操作数据,但我不知道如何在我的 Canopy 输出区域查看输出。
有谁知道将数据从 excel 导入到 python 的简单方法,对其进行处理然后将其返回到 excel,而无需保存文件,将其加载到 python 中,处理数据并覆盖现有文件?
@xl_func("string[] name, var[] day, string[] method, string[] currency, numpy_array amounts, date[] dates: dataframe")
def test(name, day, method, currency, amounts, dates):
df_name = DataFrame(name, columns = ['Name'])
df_method = DataFrame(method, columns = ['Method']).ix[1:]
df_currency = DataFrame(currency, columns = ['Currency']).ix[1:]
df = df_name.join(df_method).join(df_currency)
cols = ['Name', 'Currency', 'Method']
df = df[cols]
return DataFrame(dates)