<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to convert Intersplunk's readResults() to dataframe? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-convert-Intersplunk-s-readResults-to-dataframe/m-p/215034#M2840</link>
    <description>&lt;P&gt;You better to use service jobs as following:&lt;/P&gt;

&lt;H1&gt;Function to Perform a Splunk search&lt;/H1&gt;

&lt;P&gt;def execute_query(searchquery_normal, &lt;BR /&gt;
                  kwargs_normalsearch={"exec_mode": "normal"}, &lt;BR /&gt;
                  kwargs_options={"output_mode": "csv", "count": 1000000}):&lt;BR /&gt;
    # Execute Search&lt;BR /&gt;
    job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# A normal search returns the job's SID right away, so we need to poll for completion
while True:
    while not job.is_ready():
        pass
    stats = {"isDone": job["isDone"], "doneProgress": float(job["doneProgress"])*100, 
             "scanCount": int(job["scanCount"]), "eventCount": int(job["eventCount"]), 
             "resultCount": int(job["resultCount"])}
    status = ("\r%(doneProgress)03.1f%%   %(scanCount)d scanned   " 
              "%(eventCount)d matched   %(resultCount)d results") % stats

    sys.stdout.write(status + '\n')
    sys.stdout.flush()
    if stats["isDone"] == "1":
        sys.stdout.write("\nDone!")
        break
    time.sleep(0.5)

# Get the results and display them
csv_results = job.results(**kwargs_options).read()
job.cancel()

for row in csv_results:
            if row[0] not in (None, ""):
                df = pd.read_csv(StringIO.StringIO(csv_results), encoding='utf8', sep=',', low_memory=False)
                df.to_csv(filename_new, sep=',', encoding='utf-8')
                break
            break
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can find whole project from following:&lt;BR /&gt;
&lt;A href="https://github.com/selcukozer/splunk_python" target="_blank"&gt;https://github.com/selcukozer/splunk_python&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 19:24:26 GMT</pubDate>
    <dc:creator>selcukozer</dc:creator>
    <dc:date>2020-09-29T19:24:26Z</dc:date>
    <item>
      <title>How to convert Intersplunk's readResults() to dataframe?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-convert-Intersplunk-s-readResults-to-dataframe/m-p/215032#M2838</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to add a Python script as a Splunk custom command and I'm having trouble reading the data from Intersplunk and formatting it as a pandas dataframe. I have:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;results = splunk.Intersplunk.readResults()
df = pandas.DataFrame(results)
ip_list = df['ip'].tolist()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I'm converting the list of dictionaries returned by &lt;CODE&gt;readResults()&lt;/CODE&gt; to a pandas DF and then extracting what would be the csv "ip" column as a list. But I am getting an error on that last code line.&lt;/P&gt;

&lt;P&gt;I have also tried &lt;CODE&gt;df = pandas.DataFrame.from_records(results)&lt;/CODE&gt; and &lt;CODE&gt;ip_list = df['ip'].values.tolist()&lt;/CODE&gt;, but it's not working.&lt;/P&gt;

&lt;P&gt;I'd appreciate any help.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 14:32:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-convert-Intersplunk-s-readResults-to-dataframe/m-p/215032#M2838</guid>
      <dc:creator>agnesramos</dc:creator>
      <dc:date>2016-08-08T14:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Intersplunk's readResults() to dataframe?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-convert-Intersplunk-s-readResults-to-dataframe/m-p/215033#M2839</link>
      <description>&lt;P&gt;Some more info will help - What error are you getting? What does your 'ip' field look like?&lt;/P&gt;

&lt;P&gt;umm and also, why are you converting it to a DF just to go back to a list right away?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 21:31:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-convert-Intersplunk-s-readResults-to-dataframe/m-p/215033#M2839</guid>
      <dc:creator>danbar6</dc:creator>
      <dc:date>2017-12-01T21:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Intersplunk's readResults() to dataframe?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-convert-Intersplunk-s-readResults-to-dataframe/m-p/215034#M2840</link>
      <description>&lt;P&gt;You better to use service jobs as following:&lt;/P&gt;

&lt;H1&gt;Function to Perform a Splunk search&lt;/H1&gt;

&lt;P&gt;def execute_query(searchquery_normal, &lt;BR /&gt;
                  kwargs_normalsearch={"exec_mode": "normal"}, &lt;BR /&gt;
                  kwargs_options={"output_mode": "csv", "count": 1000000}):&lt;BR /&gt;
    # Execute Search&lt;BR /&gt;
    job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# A normal search returns the job's SID right away, so we need to poll for completion
while True:
    while not job.is_ready():
        pass
    stats = {"isDone": job["isDone"], "doneProgress": float(job["doneProgress"])*100, 
             "scanCount": int(job["scanCount"]), "eventCount": int(job["eventCount"]), 
             "resultCount": int(job["resultCount"])}
    status = ("\r%(doneProgress)03.1f%%   %(scanCount)d scanned   " 
              "%(eventCount)d matched   %(resultCount)d results") % stats

    sys.stdout.write(status + '\n')
    sys.stdout.flush()
    if stats["isDone"] == "1":
        sys.stdout.write("\nDone!")
        break
    time.sleep(0.5)

# Get the results and display them
csv_results = job.results(**kwargs_options).read()
job.cancel()

for row in csv_results:
            if row[0] not in (None, ""):
                df = pd.read_csv(StringIO.StringIO(csv_results), encoding='utf8', sep=',', low_memory=False)
                df.to_csv(filename_new, sep=',', encoding='utf-8')
                break
            break
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can find whole project from following:&lt;BR /&gt;
&lt;A href="https://github.com/selcukozer/splunk_python" target="_blank"&gt;https://github.com/selcukozer/splunk_python&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:24:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-convert-Intersplunk-s-readResults-to-dataframe/m-p/215034#M2840</guid>
      <dc:creator>selcukozer</dc:creator>
      <dc:date>2020-09-29T19:24:26Z</dc:date>
    </item>
  </channel>
</rss>

