Skip to content

Commit 2e62758

Browse files
authored
Added a dataframe feature
new method "dataframe" added, which returns a pandas dataframe Usage: query.dataframe() optional arguments: size: maximum results to return start: index of first result to be returned
1 parent 8fe05e6 commit 2e62758

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

intermine/query.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
from copy import deepcopy
33
from xml.dom import minidom, getDOMImplementation
4+
from pandas import DataFrame
45

56
from intermine.util import openAnything, ReadableException
67
from intermine.pathfeatures import PathDescription, Join, SortOrder, SortOrderList
@@ -1387,6 +1388,31 @@ def rows(self, start=0, size=None):
13871388
"""
13881389
return self.results(row="rr", start=start, size=size)
13891390

1391+
def dataframe(self, start=0, size=None):
1392+
"""
1393+
Returns a pandas.DataFrame
1394+
==================================
1395+
1396+
Usage::
1397+
>>> query.dataframe()
1398+
1399+
@param start: the index of the first result to return (default = 0)
1400+
@type start: int
1401+
@param size: The maximum number of results to return (default = all)
1402+
@type size: int
1403+
@rtype: dataframe<pandas.core.frame.DataFrame>
1404+
1405+
"""
1406+
dict = {}
1407+
query = self.results(row="dict", start=start, size=size)
1408+
for i in query.view:
1409+
dict[i] = []
1410+
for row in query:
1411+
for i in dict:
1412+
dict[i].append(row[i])
1413+
df = DataFrame(data=dict)
1414+
return df
1415+
13901416
def summarise(self, summary_path, **kwargs):
13911417
"""
13921418
Return a summary of the results for this column.

0 commit comments

Comments
 (0)