Answer the question
In order to leave comments, you need to log in
How to create a DataFrame?
Hello! I need to write the results of the program launched through the sub process into a csv table. They suggested that this can be done using the pandas libraries, based on the results, create a DataFrame, and then create a csv file where everything will be written. All the values that I specify in the DataFrame get into the table, but the result of the program’s work is not there, but it is displayed in the terminal. The screenshot shows what appears in the table. Please tell me how to do it. Thanks in advance
Here is the code:
import pandas as pd
import subprocess
from time import sleep
p=subprocess.Popen(['/usr/bin/python3', '/home/roman/PycharmProjects/uznaemfileID/fileid.py', 'stdout=subprocess.PIPE', 'stderr=subprocess.STDOUT'])
result=p.stderr
sleep(1)
#create a pandas dataframe
df = pd.DataFrame({'file_id': [result]})
#create a csv file
df.to_csv("data.csv")
p.terminate()
Answer the question
In order to leave comments, you need to log in
I suspect it was meant to be:
p=subprocess.Popen(['/usr/bin/python3', '/home/roman/PycharmProjects/uznaemfileID/fileid.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result=p.stdout.read()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question