Python – Take Pprint Export and Convert to Pandas DataFrame

I am NEW to python and am learning it to pull data into Power BI. By new, I mean this is my first project. My current use case is to extract data regarding tasks from Asana. I have successfully copied, pasted, and adjusted the python code that Asana offers and am getting data regarding my tasks. I am struggling with how to take that data and turn it into a dynamic table using pandas so that I can pull it into Power BI. We don’t have an enterprise license with Asana, which is why I need to use python instead of their connector. I have already imported pandas and have that available.

Here is the code to pull the tasks from Asana (sensitive info modified):

import asana
from asana.rest import ApiException
from pprint import pprint

configuration = asana.Configuration()
configuration.access_token = 'Abcd123'
api_client = asana.ApiClient(configuration)

tasks_api_instance = asana.TasksApi(api_client)
opts = {
    'project': "123456789",
    'opt_fields': "name,actual_time_minutes,assignee,assignee.name,"
                  "custom_fields,custom_fields.name,custom_fields.display_value,"
                  "due_on,start_on,"
                  "permalink_url"
}

try:
    tasks = tasks_api_instance.get_tasks(opts)
    for task in tasks:

        pprint(task)
except ApiException as e:
    print("Exception when calling TasksApi->get_tasks: %sn" % e)

Here is a sample of the output that I get when I run it:

{'actual_time_minutes': None,
 'assignee': {'gid': '1104899036650576', 'name': 'Jane Doe'},
 'custom_fields': [{'display_value': None,
                    'gid': '1207268873906857',
                    'name': 'Estimated time'},
                   {'display_value': None,
                    'gid': '1207268873683694',
                    'name': 'Priority'},
                   {'display_value': 'Closed',
                    'gid': '1207268873683699',
                    'name': 'Status'},
                   {'display_value': 'https://dev.azure.com/clientsite',
                    'gid': '1207269260215808',
                    'name': 'Link to DevOps'},
                   {'display_value': None,
                    'gid': '1207277291413677',
                    'name': 'Sprint'},
                   {'display_value': '4265',
                    'gid': '1207269541980519',
                    'name': 'DevOps ID'}],
 'due_on': '2024-04-05',
 'gid': '1207277618607073',
 'name': 'Update Javascript on this Thing',
 'start_on': None}
{'actual_time_minutes': None,
 'assignee': None,
 'custom_fields': [{'display_value': None,
                    'gid': '1207268873906857',
                    'name': 'Estimated time'},
                   {'display_value': None,
                    'gid': '1207268873683694',
                    'name': 'Priority'},
                   {'display_value': 'On Hold',
                    'gid': '1207268873683699',
                    'name': 'Status'},
                   {'display_value': 'https://dev.azure.com/clientsite',
                    'gid': '1207269260215808',
                    'name': 'Link to DevOps'},
                   {'display_value': None,
                    'gid': '1207277291413677',
                    'name': 'Sprint'},
                   {'display_value': '3867',
                    'gid': '1207269541980519',
                    'name': 'DevOps ID'}],
 'due_on': '2023-12-12',
 'gid': '1207277735170286',
 'name': 'Create Workflow to Do This',
 'start_on': None}
{'actual_time_minutes': None,
 'assignee': None,
 'custom_fields': [{'display_value': None,
                    'gid': '1207268873906857',
                    'name': 'Estimated time'},
                   {'display_value': None,
                    'gid': '1207268873683694',
                    'name': 'Priority'},
                   {'display_value': 'New',
                    'gid': '1207268873683699',
                    'name': 'Status'},
                   {'display_value': 'https://dev.azure.com/clientsite',
                    'gid': '1207269260215808',
                    'name': 'Link to DevOps'},
                   {'display_value': None,
                    'gid': '1207277291413677',
                    'name': 'Sprint'},
                   {'display_value': '4354',
                    'gid': '1207269541980519',
                    'name': 'DevOps ID'}],
 'due_on': None,
 'gid': '1207277611759913',
 'name': 'Write the Script for this Thing',
 'start_on': None}
{'actual_time_minutes': None,
 'assignee': {'gid': '1104899036650576', 'name': 'John Doe'},
 'custom_fields': [{'display_value': None,
                    'gid': '1207268873906857',
                    'name': 'Estimated time'},
                   {'display_value': None,
                    'gid': '1207268873683694',
                    'name': 'Priority'},
                   {'display_value': 'Closed',
                    'gid': '1207268873683699',
                    'name': 'Status'},
                   {'display_value': 'https://dev.azure.com/clientsite',
                    'gid': '1207269260215808',
                    'name': 'Link to DevOps'},
                   {'display_value': None,
                    'gid': '1207277291413677',
                    'name': 'Sprint'},
                   {'display_value': '4353',
                    'gid': '1207269541980519',
                    'name': 'DevOps ID'}],
 'due_on': None,
 'gid': '1207277863543561',
 'name': 'Go Do This Important Thing',
 'start_on': None}

As you can see, there are multiple records that are returned. The values that I need to grab from this are: name,assignee.name,Status,Estimated time,actual_time_minutes. I need to build a DataFrame for this data and I need to essentially run each record returned through a loop so that it is a row. The data returned will change though so I can’t give it the values that it should display. I need to tell it which ‘column’ in the returned data to use instead.

I appreciate ALL help, but as I’m trying to learn this, I would also appreciate any explanations on why I should do it a certain way.

Using a separate query, I was able to successfully build a dummy test table to get the idea of building a table with pandas. However, I am at a loss on how to get from my data above to something that replicates the results of this.

import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
df.loc[len(df)] = ['Barbara',25]
print (df)

Results from pandas test:

      Name  Age
0     Alex   10
1      Bob   12
2   Clarke   13
3  Barbara   25

Process finished with exit code 0

New contributor

dkgibbs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật