Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only

Tip: Jupyter Notebook Pandas Column Heading with space characters

  • 1.  Tip: Jupyter Notebook Pandas Column Heading with space characters

    Posted Tue April 07, 2020 09:22 AM
    I have been finding issues working with column headings in a pandas dataframe when accessing data from an FM package,

    I have found issues with columns that have spaces in their column heading labels.

    create a dataframe that pulls the Query subjects in the "Sales (query)" folder.
    data2 = CADataConnector.read_data(path=".public_folders/Samples/Models/GO data warehouse (query)",
    folder_name=["Sales (query)"])

    Create a dataframe that pulls all the columns from 3 query subjects
    qs = CADataConnector.read_data(path=".public_folders/Samples/Models/GO data warehouse (query)",
    query_subject=[data2['Query Subject'][0], data2['Query Subject'][11], data2['Query Subject'][9]])

    Using this lambda function replaces the spaces in labels with an underscore characters
    tidyqs = qs.rename(columns=lambda x: x.lower().replace(' ', '_'))

    Manipulating the dataframes is easier when using columns with no spaces.

    ------------------------------
    Ian Cloves
    ------------------------------

    #CognosAnalyticswithWatson