subgrounds.dataframe_utils module
Pandas DataFrame utility module containing functions related to the formatting of GraphQL JSON data into DataFrames.
- subgrounds.dataframe_utils.gen_columns(data, prefix='')
- subgrounds.dataframe_utils.fmt_cols(df, col_map)
- class subgrounds.dataframe_utils.DataFrameColumns(key, fpaths)
Bases:
objectHelper class that holds data related to the shape of a DataFrame
- combine(other)
Returns new DataFrameColumns containing the union of
selfandother's columns- Parameters
other (DataFrameColumns) -- Columns to be combined to
self- Returns
- New
DataFrameColumnscontaining the union of selfandother
- New
- Return type
- mk_df(data, path_map)
Formats the JSON data
datainto a DataFrame containing the columns defined inself.
- subgrounds.dataframe_utils.columns_of_selections(selections)
Generates a list of DataFrame columns specifications based on a list of
Selectiontrees.- Parameters
- Returns
The list of DataFrame columns specifications
- Return type
- subgrounds.dataframe_utils.df_of_json(json_data, fpaths, columns=None, concat=False)
Formats the JSON data
json_datainto Pandas DataFrames, flattening the data in the process.Depending on the request's fieldpaths, either one or multiple dataframes will be returned based on how flattenable the response data is.
fpathsis a list ofFieldPathobjects corresponding to the set of fieldpaths that were used to get the response datajson_data.columnsis an optional argument used to rename the dataframes(s) columns. The length ofcolumnsmust be the same as the number of columns of all returned dataframes.concatindicates whether or not the resulting dataframes should be concatenated together. The dataframes must have the same number of columns, as well as the same column names (which can be set using thecolumnsargument).- Parameters
- Returns
The resulting dataframe(s)
- Return type
pd.DataFrame | list[pd.DataFrame]