【问题标题】:How to convert CSV to Excel using Python with pandas in Apache NiFi?如何在 Apache NiFi 中使用 Python 和 pandas 将 CSV 转换为 Excel?
【发布时间】:2021-08-26 11:31:54
【问题描述】:

如何使用处理器ExecuteStreamCommandExecuteScript 将CSV 原始源从GenerateFlowFile 处理器转换为Excel 文件?

以及如何运行 Python 虚拟环境 (env) 以使用 Python 项目中的依赖项?

【问题讨论】:

    标签: apache-nifi data-processing


    【解决方案1】:

    将您的 CSV 封装到 Python 脚本中的 Excel 逻辑并使用 ExecuteStreamCommand 调用它。像下面这样开始并根据您的要求进行更改:

    import pandas as pd
    
    # Reading the csv file content from NiFi
    csv_df = pd.read_csv(sys.stdin)
      
    # send excel file back to NiFi
    csv_df.to_excel(sys.stdout.buffer, index=False)
    

    将您的ExecuteStreamCommand 处理器配置为:

    【讨论】:

    • 只是从 csv_df.to_excel(sys.stdout, index = False) 转换为 csv_df.to_excel(sys.stdout.buffer,index=False) 非常感谢您
    • 如果回答有助于解决您的问题,请采纳,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    相关资源
    最近更新 更多