Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting a empty dataframe using pandas

I’m using pandas to create a dataframe in python, but I get only the columns when I try this.

This is my code:

def suitecrm_get_account_data(account_id):
    suitecrm_acces_token()
    url = base_url+'/V8/module/Accounts/'+account_id
    headers = {'Authorization': 'Bearer '+suitecrm_acces_token.access_token}
    response= requests.request("GET", url , headers=headers)
    account_attributes = json.loads(response.text)['data']['attributes']
    print(account_attributes)
    df = pd.DataFrame(account_attributes)
    print(df)
print(account_attributes)
{'name': '5D Investments', 'date_entered': '2021-12-13T15:17:00+00:00', 'date_modified': '2021-12-13T15:17:00+00:00', 'modified_user_id': '1', 'modified_by_name': 'Administrator', 'created_by': '1', 'created_by_name': 'Administrator', 'description': '', 'deleted': '0', 'created_by_link': '', 'modified_user_link': '', 'assigned_user_id': '1', 'assigned_user_name': 'Administrator', 'assigned_user_link': '', 'SecurityGroups': '', 'account_type': 'Customer', 'industry': 'Other', 'annual_revenue': '', 'phone_fax': '', 'billing_address_street': '48920 San Carlos Ave', 'billing_address_street_2': '', 'billing_address_street_3': '', 'billing_address_street_4': '', 'billing_address_city': 'Persistance', 'billing_address_state': 'NY', 'billing_address_postalcode': '', 'billing_address_country': 'USA', 'rating': '', 'phone_office': '(893) 969-8036', 'phone_alternate': '', 'website': 'www.kidqa.co.jp', 'ownership': '', 'employees': '', 'ticker_symbol': '', 'shipping_address_street': '48920 San Carlos Ave', 'shipping_address_street_2': '', 'shipping_address_street_3': '', 'shipping_address_street_4': '', 'shipping_address_city': 'Persistance', 'shipping_address_state': 'NY', 'shipping_address_postalcode': '', 'shipping_address_country': 'USA', 'email1': 'the.beans.qa@example.tw', 'email_addresses_primary': '', 'email_addresses': '', 'email_addresses_non_primary': '', 'parent_id': '', 'sic_code': '', 'parent_name': '', 'members': '', 'member_of': {}, 'email_opt_out': '0', 'invalid_email': '0', 'cases': '', 'email': '', 'tasks': '', 'notes': '', 'meetings': '', 'calls': '', 'emails': '', 'documents': '', 'bugs': '', 'contacts': '', 'opportunities': '', 'project': '', 'leads': '', 'campaigns': '', 'campaign_accounts': {}, 'campaign_id': '', 'campaign_name': '', 'prospect_lists': '', 'aos_quotes': '', 'aos_invoices': '', 'aos_contracts': '', 'jjwg_maps_geocode_status_c': '', 'jjwg_maps_lng_c': '0.00000000', 'jjwg_maps_address_c': '', 'jjwg_maps_lat_c': '0.00000000'}
print(ds)
Empty DataFrame
Columns: [name, date_entered, date_modified, modified_user_id, modified_by_name, created_by, created_by_name, description, deleted, created_by_link, modified_user_link, assigned_user_id, assigned_user_name, assigned_user_link, SecurityGroups, account_type, industry, annual_revenue, phone_fax, billing_address_street, billing_address_street_2, billing_address_street_3, billing_address_street_4, billing_address_city, billing_address_state, billing_address_postalcode, billing_address_country, rating, phone_office, phone_alternate, website, ownership, employees, ticker_symbol, shipping_address_street, shipping_address_street_2, shipping_address_street_3, shipping_address_street_4, shipping_address_city, shipping_address_state, shipping_address_postalcode, shipping_address_country, email1, email_addresses_primary, email_addresses, email_addresses_non_primary, parent_id, sic_code, parent_name, members, member_of, email_opt_out, invalid_email, cases, email, tasks, notes, meetings, calls, emails, documents, bugs, contacts, opportunities, project, leads, campaigns, campaign_accounts, campaign_id, campaign_name, prospect_lists, aos_quotes, aos_invoices, aos_contracts, jjwg_maps_geocode_status_c, jjwg_maps_lng_c, jjwg_maps_address_c, jjwg_maps_lat_c]
Index: []

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to provide an index. With one row, it can’t guess what the index should be.

df = pd.DataFrame(account_attributes,index=[0])

If you have multiple rows, then something like:

df = pd.DataFrame(account_attributes,index=range(len(account_attributes)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading