Is there a way to output the value in the form of a data frame in the Python for iteration syntax?

Asked 2 years ago, Updated 2 years ago, 29 views

It's a code to get net sales data from Daishin Securities API. Someone else wrote it.

It is a format that designates an item with the SetInputValue method and requests and outputs it as BlockRequest().The securities company seems to have limited the data that can be received at once, so that the value continues to come out through repeated phrases.

What I'm curious about is that I'd like to have it lined up like an Excel file. The result is as if it's coming out of Atom

20161228 Person: XXXX Foreigner: XXXXX Agency:XXXXXX

It comes out like this. I think I need to use a data frame, but I can't imagine what to do. Please give us your opinions. Thank you. (__)

import win32com.client
import pandas
import numpy


# Create Object
inCpSvr7254 = win32com.client.Dispatch("CpSysDib.CpSvr7254")

inCpSvr7254.SetInputValue(0, "A003540")
inCpSvr7254.SetInputValue(1, 6)
inCpSvr7254.SetInputValue(2, 20110101)
inCpSvr7254.SetInputValue(3, 20161227)
inCpSvr7254.SetInputValue(4, '0')
inCpSvr7254.SetInputValue(5, 0)

inCpSvr7254.BlockRequest()

count = inCpSvr7254.GetHeaderValue(1)
print(count)

for i in range(count):

    print(inCpSvr7254.GetDataValue(0, i))
    print("Personal:", inCpSvr7254.GetDataValue(1, i))
    print("Foreigner: ", inCpSvr7254.GetDataValue(2, i)))
    print("Engine system: ", inCpSvr7254.GetDataValue(3, i))")

while inCpSvr7254.Continue:
    inCpSvr7254.BlockRequest()
    count = inCpSvr7254.GetHeaderValue(1)
    print(count)

    for i in range(count):
        print("-----------------------------")
        print(inCpSvr7254.GetDataValue(0, i))
        print("Personal:", inCpSvr7254.GetDataValue(1, i))
        print("Foreigner: ", inCpSvr7254.GetDataValue(2, i)))
        print("Engine system: ", inCpSvr7254.GetDataValue(3, i))")

api python

2022-09-22 20:08

1 Answers

You don't have to handle all of the data on the code.

When I need to handle the data, I tend to divide it into commas first, then take it to Excel and process it. That would make it a lot easier.

If it's a repetitive task or if you need to keep accumulating data, it's a good idea to create a separate table in the DB and store it there. Are you only using it to load data now? I think I need to store data well for system trading, so I will need a DB that can stack data personally.

What you're trying to do now is to change the line in the last line when you print it out, right?

print(inCpSvr7254.GetDataValue(0, i))
print("Personal:", inCpSvr7254.GetDataValue(1, i))
print("Foreigner: ", inCpSvr7254.GetDataValue(2, i)))
print("Engine system: ", inCpSvr7254.GetDataValue(3, i))")

Please change this part as below.

print(inCpSvr7254.GetDataValue(0, i),end="")
print("Personal:", inCpSvr7254.GetDataValue(1, i), end="")
print ("foreigner: ", inCpSvr7254.GetDataValue(2, i), end="")
print("Engine system: ", inCpSvr7254.GetDataValue(3, i))")

If you write end=", you do not change the line when you print it out. You'd better not write down individuals/foreigners/institutionalities in the print statement.


2022-09-22 20:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.