In [1]:
# hide ssl warnings for this example.
import requests
requests.packages.urllib3.disable_warnings()
This is a short example on how to easily build a Pandas DataFrame from a Foundset.
Here you can find information about Pandas and DataFrames and how you can work with these data structures when analysing data.
For this example, make sure to first install Pandas (pip install pandas
) and optionally Matplotlib (pip install matplotlib
).
In [2]:
import fmrest
from pandas.plotting import parallel_coordinates
from matplotlib import pyplot as plt
%matplotlib inline
First, we create our server instance just like in the examples before.
In [3]:
fms = fmrest.Server('https://10.211.55.15',
user='admin',
password='admin',
database='Contacts',
layout='Iris',
verify_ssl=False,
#type_conversion=True #Danger!
)
fms.login()
Out[3]:
If you have numbers in text fields or want to work with dates, you can try out type_conversion=True
.
Note: As this "type-guessing" can, at times, lead to unexpected results, I strongly recommended you to do the type conversion yourself when working with your own "known" data fields.
Let's fetch all data from our Iris layout as specified above.
(When you have more than 100 records to fetch, make sure to specify the limit
parameter as the Data API defaults to 100 records.)
In [4]:
foundset = fms.get_records(limit=150)
foundset
Out[4]:
Now that we have our Foundset instance, the only thing we need to do is to call the to_df
method. This will give us a Pandas DataFrame.
Let's look at the first 5 rows.
In [5]:
df = foundset.to_df()
df.head()
Out[5]:
Since we are not interested in recordId
or modId
, we just drop them.
In [6]:
df.drop(['recordId', 'modId'], axis=1, inplace=True)
df.head()
Out[6]:
Before working with your data, check that the types are OK (previous versions of the Data API always returned strings and ignored the data type set in your DB schema).
In [7]:
df.dtypes
Out[7]:
With your DataFrame ready, you can go on analyzing and plotting your data as you wish...
In [8]:
plt.figure(figsize=(12, 12))
parallel_coordinates(df, 'class')
Out[8]:
Learn more here: https://pandas.pydata.org/pandas-docs/stable/index.html