Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在NiFi中读取ExecuteStreamCommand处理器中的文件_Python_Hadoop_Google Cloud Platform_Apache Nifi - Fatal编程技术网

Python 如何在NiFi中读取ExecuteStreamCommand处理器中的文件

Python 如何在NiFi中读取ExecuteStreamCommand处理器中的文件,python,hadoop,google-cloud-platform,apache-nifi,Python,Hadoop,Google Cloud Platform,Apache Nifi,我的最终目标是屏蔽一个特定文件中的数据。我想把文件从一个地方移到另一个地方。在这个传输过程中,我必须使用Python脚本屏蔽数据。因此,我设计了以下流程: GetFile > ExecuteStreamCommmand > PutFile 我使用pandas设计了一个Python脚本。我在Google云平台上创建的虚拟机上运行这个NiFi,我在那里安装了Python-2.7和NiFi-1.9.1。以下是我的熊猫代码: import pandas as pd readFile = p

我的最终目标是屏蔽一个特定文件中的数据。我想把文件从一个地方移到另一个地方。在这个传输过程中,我必须使用Python脚本屏蔽数据。因此,我设计了以下流程:

GetFile > ExecuteStreamCommmand > PutFile
我使用
pandas
设计了一个
Python
脚本。我在
Google云平台上创建的虚拟机上运行这个
NiFi
,我在那里安装了
Python-2.7
NiFi-1.9.1
。以下是我的熊猫代码:

import pandas as pd
readFile = pd.read_csv("/path",sep=" ",header=None)
readFile.columns = ['IP']
readFile['IP'] = readFile['IP'].replace(regex='((?<=[0-9])[0-9]|(?<=\.)[0-9])',value='X')
readFile.to_csv("/path", sep=' ')
将熊猫作为pd导入
readFile=pd.read\u csv(“/path”,sep=”“,header=None)
readFile.columns=['IP']
readFile['IP']=readFile['IP'].replace(regex='(?

流文件的内容作为
stdin
stream传递到命令(在您的例子中是python)中

因此,您必须使用以下代码:

readFile = pd.read_json(sys.stdin)


另一方面,如果需要对流文件应用regexp replace,可以尝试使用processor而不是
ExecuteStreamCommand

,您可能需要在nifi注册的卷中提供python.py文件


例如opt/nifi/nifi current/如果是docker图像

你在“Python”中做什么代码?。似乎你只是在替换文件中的某些内容,对吗?我们无法在ExecuteStream命令处理器中读取传入的流文件,但我想在ExecuteStream命令处理器中使用正则表达式来屏蔽数据。那么我该如何做呢?在这种情况下,流将是什么?似乎你可以在ReplaceText处理器本身中屏蔽数据,而无需使用Python s感谢@daggett。我有柱状数据。那么替换文本处理器对我来说是一个不错的选择吗?另外,我可以使用read_csv方法读取数据,因为我想提到分隔符吗?