(search_obj, output_format, show_headers)
return result
Format search result output.

    Args:
        search_obj: API Search object.
        output_format: The format to use.
        show_headers: Boolean indicating if header row should be displayed.

    Returns:
        Search results in the requested output format.
Format search result output.
Format search result output .
def format_output(search_obj, output_format, show_headers):
    """Format search result output.

    Args:
        search_obj: API Search object.
        output_format: The format to use.
        show_headers: Boolean indicating if header row should be displayed.

    Returns:
        Search results in the requested output format.
    """
    dataframe = search_obj.to_pandas()

    # Label is being set regardless of return_fields. Remove if it is not in
    # the list of requested fields.
    if 'label' not in search_obj.return_fields:
        dataframe = dataframe.drop(columns=['label'])

    result = None
    if output_format == 'text':
        result = dataframe.to_string(index=False, header=show_headers)
    elif output_format == 'csv':
        result = dataframe.to_csv(index=False, header=show_headers)
    elif output_format == 'tabular':
        if show_headers:
            result = tabulate(
                dataframe, headers='keys', tablefmt='psql', showindex=False)
        else:
            result = tabulate(dataframe, tablefmt='psql', showindex=False)

    return result
def format_output ( search_obj , output_format , show_headers ) : dataframe = search_obj . to_pandas ( ) # Label is being set regardless of return_fields. Remove if it is not in # the list of requested fields. if 'label' not in search_obj . return_fields : dataframe = dataframe . drop ( columns = [ 'label' ] ) result = None if output_format == 'text' : result = dataframe . to_string ( index = False , header = show_headers ) elif output_format == 'csv' : result = dataframe . to_csv ( index = False , header = show_headers ) elif output_format == 'tabular' : if show_headers : result = tabulate ( dataframe , headers = 'keys' , tablefmt = 'psql' , showindex = False ) else : result = tabulate ( dataframe , tablefmt = 'psql' , showindex = False ) return result