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
dkgibbs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1