python - 使用 Pyxll 将数组从 Excel 导入到 Python Pandas

标签 python excel pandas pyxll

我拼命尝试使用 Pyxll 来编写一些 excel 函数来获取一堆数组,将它们加载到 Python 中,将它们转换为 pandas DataFrame,稍微处理一下数据,然后返回最终的 DataFrame。 现在,为了返回我找到的 DataFrame pyxll examples ,但无论我如何尝试,我似乎都无法将我加载的 excel 数组转换为我可以使用的 pandas DataFrame。

例如,我尝试使用下面的代码,但没有成功。也许如果我有某种方式知道 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)

最佳答案

PyXLL 可以使用自定义类型接受和返回 pandas 数据帧。

看看这个例子: https://github.com/pyxll/pyxll-examples/blob/master/pandas

要查看输出,请查看日志文件。 要使用 IPython 提示在 Python 中进行交互,请使用以下示例: https://github.com/pyxll/pyxll-examples/tree/master/ipython

坚持使用函数比求助于命名范围要好得多。

您也可以使用 PyXLL 来注册键盘快捷键。有关自动调整数组公式输出大小的快捷方式,请参见此示例: https://github.com/pyxll/pyxll-examples/blob/master/shortcuts/resize_array_formula.py

如果您需要更多帮助,请联系支持以获得快速响应。

关于python - 使用 Pyxll 将数组从 Excel 导入到 Python Pandas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26048137/

相关文章:

arrays - UDF 中变量的动态数量

perl - 如何通过 Excel 中的 ActiveX 控件运行 Perl 脚本?

excel - 删除与图案匹配的所有 Excel 绘图图层形状

python - Pandas 打印选项

python - 打开多个txt文件并执行相同的操作

Python:匹配某些术语的字符串

python - 如何通过第二个属性对已经排序的数组进行排序?

python - Pandas 数据框 : Fill Missing Months

python - 代码不从字典中删除所需的值

python - 刷新 GAE 中的输出?