Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numpy newbie question
#5
OK, got you close -
Since numpy is a numerical oriented library, I decided to use Pandas.
import pandas as pd
from todoist_api_python.api import TodoistAPI

# Fetch tasks synchronously
def get_tasks_sync():
    api = TodoistAPI("XXXXXX")
    try:
        tasks = api.get_tasks()
        return tasks
    except Exception as error:
        print(error)

tasklist = get_tasks_sync()
itemlist = [] #start a list of the tasks
for task_obj in tasklist: # recognize that you have a set of Task objects to convert to strings
    task = task_obj.__str__() # convert to a string
    item = task[5:-1] # Get rid of "Task("
    item = item[0:-3] # Get rid of closing parens
    item = item.split(',') # Now split the string on commas into the individual fields
    itemlist.append(item) # Add this list of fields to the list of tasks
    
df = pd.DataFrame(itemlist) #Turn it into a dataframe
df.head() #show result
Reply


Messages In This Thread
numpy newbie question - by bcwilly_ca - Feb-08-2023, 02:20 AM
RE: numpy newbie question - by noisefloor - Feb-08-2023, 06:28 PM
RE: numpy newbie question - by bcwilly_ca - Feb-08-2023, 11:10 PM
RE: numpy newbie question - by noisefloor - Feb-09-2023, 02:45 PM
RE: numpy newbie question - by jefsummers - Feb-10-2023, 05:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 1,458 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 1,542 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Newbie question about switching between files - Python/Pycharm Busby222 3 1,421 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  Newbie.... run for cover. OpenCV question Stevolution2023 2 1,686 Apr-12-2023, 12:57 PM
Last Post: Stevolution2023
  Question from complete python's newbie Davicom 3 3,147 Jun-09-2021, 06:09 PM
Last Post: bowlofred
  Newbie question about running Python via GUI on OSX ejwjohn 8 4,912 Feb-05-2021, 03:20 PM
Last Post: Larz60+
  super newbie question: escape character tsavoSG 3 3,299 Jan-13-2021, 04:31 AM
Last Post: tsavoSG
  newbie question....importing a created class ridgerunnersjw 5 3,679 Oct-01-2020, 07:59 PM
Last Post: ridgerunnersjw
  Dumb newbie question JonEdward 5 4,582 Jul-22-2020, 10:06 PM
Last Post: snippsat
  Newbie Question juljan 4 3,653 Jan-13-2020, 03:07 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020