Hi
I have used a Python SDK to extract data from Splunk.
In the image you can see an example of the output.
I want to send that information to a DataFrame.
Any clues will be helpful.
Thank yoi
Hi
I have used a Python SDK to extract data from Splunk.
In the image you can see an example of the output.
I want to send that information to a DataFrame.
Any clues will be helpful.
Thank yoi
Assuming that you have those in a vector Dv
,
vcat(DataFrame.(Dv)...)
would work. You could also convert them to NamedTuples instead of Dicts and then construct the DataFrame.
That doesn’t change anything. You can either collect the Dict
s into a vector during your loop and use my suggestion afterwards, or you can create one-row DataFrame
s while you iterate (using df = DataFrame(item)
) and collect them into a single one afterwards (again using vcat
).
This is the second option you can create one-row DataFrames while you iterate
:
It seems to be working.
But how can I see the dataframe?
That is not going to be doing what you want, you aren’t actually accumulating anything. Try this
Dv = Vector{Dict}()
for item in reader
push!(Dv,item)
end
df=vcat(DataFrame.(Dv)...)
And, just taking a guess here,
df=vcat(DataFrame.(reader)...)
would probably work (since I see you are just printing with the loop anyway).
This is what I get
You need to using DataFrames
I think is the same problem I have with Python:
JULIA
The iteration never accumulates anything.
Can you give a MWE with code written in backticks, as follows, rather than screenshots?
```
Your code here
```
It seems like reader
might be empty. Having a MWE will help determine that that’s the problem.
This is the code. It is now working!!!
I used “collect”.
results=pyimport("splunklib.results")
kwargs_oneshot = (earliest_time= "2019-09-07T12:00:00.000-07:00",
latest_time= "2019-09-09T12:00:00.000-07:00",
count=0)
searchquery_oneshot = "search index=iis | lookup geo_BST_ONT longitude as sLongitude, latitude as sLatitude | stats count by featureId | geom geo_BST_ONT allFeatures=True | head 2"
oneshotsearch_results = service.jobs.oneshot(searchquery_oneshot; kwargs_oneshot...)
# Get the results
reader = results.ResultsReader(oneshotsearch_results)
# collect them into an array
Dv = collect(reader)
using DataFrames
df=vcat(DataFrame.(Dv)...)