Result in a Python Dataframe

Asked

Viewed 74 times

0

I have the following code:

import numpy as np
import pandas as pd
import psutil as ps

names = []

for service in ps.win_service_iter():

    info = service.as_dict()
    listOf =  [("Name:%s; " "Display_Name:%s; " "Status:%s " % (info['name'],info['display_name'],info['status']))]

    names.append(listOf)

names

And I need the result of this to be inside a DF with the following columns: Name, Name_display, Status.

Can you help me?


I made this script also, where you put the result in DF, however, is unusable filters or LOC, I believe that by the fact that brings the result:

import numpy as np
import pandas as pd
import psutil as ps

names = []
display = []
status = []

for service in ps.win_service_iter():

    info = service.as_dict()
    listOfNames =  [("%s" % (info['name']))]
    listOfDisplay   =  [("%s" % (info['display_name']))]
    listOfStatus  =  [("%s" % (info['status']))]

    names.append(listOfNames)
    display.append(listOfDisplay)
    status.append(listOfStatus)

zippedList =  list(zip(names, display, status))

df = pd.DataFrame(zippedList, columns = ['Name' , 'Display', 'Status']) 

df
  • 1

    Your question this confused friend, can explain better?

  • I need to put the result of this for a dataframe.. the script returns me like this: ['Name:Ajrouter; Display_name:Alljoyn Router Service; Status:stopped'], ['Name:ALG; Display_name:Application Layer Gateway Service; Status:stopped '],.

  • However, when zip the list -- zippedList = list(zip(Names)), I put it in a Dataframe -- df = pd.Dataframe(zippedList, Columns = ['Name', 'Display', 'Status']) it is not usable for example with LOC, does not search for records?

  • What does it mean resultado do for? The language construct for is an iteration loop over a given and a block of actions, these actions may or may not modify or create data, but do not return data. The language construct used to return information is the function, method or property. If the question arises, the variable stores the data.

1 answer

0


You can do so:

#import numpy as np
import pandas as pd
import psutil as ps

names = []
for service in ps.win_service_iter():
    info = service.as_dict()
    names.append({
        'nome': info['name'],
        'nome_display': info['display_name'],
        'status': info['status']

    })

df = pd.DataFrame(data=names)
df

inserir a descrição da imagem aqui

  • Perfect solution, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.