Can someone explain why I get no output? The java code outputs errors in the python script just fine, but not the DataFrame that returns when the Python code is successful. Im deploying on a Python 3.4 environment with a python script that looks like this called through Java:
d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
df = pd.DataFrame(d)
df
My Java code calling the python:
private static String executePythonCorrelations() {
String dir=System.getProperty("user.home")+"/insights/";
List<String> commands = new ArrayList<>();
commands.add("python3");
commands.add(dir+"sentiment_corr_conn.py");
//commands.add(""+_categoryId);
String ret="";
try {
ProcessBuilder pb = new ProcessBuilder().command(commands);
final Process p = pb.start();
BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line="";
while ((line = output.readLine()) != null) {
ret+=line+"<br/>";
}
while ((line = error.readLine()) != null) {
ret+="ERROR: "+line+"<br/>";
}
} catch (IOException e) {
return("EXCEPTION: "+e.getMessage()+"<br/>");
}
return(ret);
}
I believe that you need print(df)
at the end. Python's interactive mode displays the value of an expression, but script mode, which is what you're using when you call it from Java, does not. In your given code, that last line of Python evaluates df
, but then you don't give it a command (verb) telling the Python run-time system what to do with the value, so it dies sitting on top of the data stack.