N
N
neuro4live2021-03-10 14:19:53
Python
neuro4live, 2021-03-10 14:19:53

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. 6048ab40eba06470422948.pngPlease 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

1 answer(s)
O
o5a, 2021-03-10
@o5a

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()

Only if this is working with Python scripts, it would be more correct to import the module and call the functions directly, without the subprocess layer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question