Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Converting Fetch results to usable forms in Jupyter Notebook

For most data analysis situations, FetchResults need to be massaged a little bit to be useful. Here, we show the typical ways FetchResults can be usedWhen using a Jupyter Notebook, C3.ai developers typically modify FetchResults for data analysis. This section shows a couple ways to convert FetchResults into easy-to-analyze forms.

Python

In python, generallyfirst, you get retrieve the 'objs' property field from the FetchResults object, and then call the toJson() function.  This The toJson() function returns an array of dictionaries each with keys equal to the requested properties fields of the fetched type. This works well with the pandas DataFrame constructor which accepts such an array. The returned DataFrame object can now be analyzed very easily. We show an example belowfetched C3.ai Type. Using the Pandas library, this array can be turned into an analysis-ready DataFrame, as the below example shows.

A Code Example in Jupyter Notebook:

Code Block
## continue from above ##
import pandas as pd
df = pd.DataFrame(raw_data.objs.toJson())
df.head()
df.drop('meta', axis=1, inplace=True)
df.drop('type', axis=1, inplace=True)
df.drop('version', axis=1, inplace=True)
df.drop('id', axis=1, inplace=True)
df.head()

Users can then use manipulate the resulting dataframe as they normally wouldDataFrame, using common programming libraries and frameworks.

ExpressionEngineFunctions

...