Legacy Dev Forum Posts

 View Only

Sign Up

How to convert data from class to list/string

  • 1.  How to convert data from class to list/string

    Posted 06-05-2025 18:20

    Wang_Jiajun | 2021-11-17 11:33:12 UTC | #1

    I got data from [apiinstance.postanalyticsusersdetailsquery(body)]. But it's class type, and can not convert to csv by using pd.jsonnormalize() as it's not list type. Do you know how to convert it class type to list/string type?


    anon11147534 | 2021-11-17 13:12:54 UTC | #2

    Hi,

    You can get the string representation using

    response = api_instance.post_analytics_users_details_query(body)
    response_str = response.__str__()

    Wang_Jiajun | 2021-11-18 00:55:46 UTC | #3

    As it's json format, and I want to use pd.json_normalize() to convert it to csv type. Do you know how to convert it to list type?


    anon11147534 | 2021-11-18 08:39:33 UTC | #4

    You could use do

    response_list = response.__dict__.items()

    But this wouldn't yield a very usable list. The best thing you can do is write your own function that extracts the properties you want into a list representation that works for you.


    system | 2021-12-19 08:40:26 UTC | #5

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 12679